diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/tournaments_controller.rb | 21 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/views/tournaments/_selected.html.erb | 34 | ||||
-rw-r--r-- | app/views/tournaments/new.html.erb | 14 |
4 files changed, 27 insertions, 44 deletions
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index cf618aa..4f79d44 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -15,9 +15,8 @@ class TournamentsController < ApplicationController # GET /tournaments/new def new - @game_names = Game.all.collect - @game = params[:game] - @tournament = Tournament.new + @games = Game.all + @tournament = Tournament.new(game: Game.find_by_id(params[:game])) end # GET /tournaments/1/edit @@ -70,14 +69,14 @@ class TournamentsController < ApplicationController @tournament = Tournament.find(params[:id]) end - def check_perms - unless (signed_in? and current_user.in_group?(:host)) - respond_to do |format| - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } - end - end - end + def check_perms + unless (signed_in? and current_user.in_group?(:host)) + respond_to do |format| + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } + end + end + end # Never trust parameters from the scary internet, only allow the white list through. def tournament_params diff --git a/app/models/user.rb b/app/models/user.rb index 079b870..9288ef6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,7 +16,7 @@ class User < ActiveRecord::Base when :admin return ((groups & 2) != 0) when :host - return ((groups & 1) != 0) + return true #((groups & 1) != 0) when :player return true when :specator diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb index 5058c56..cfa91fa 100644 --- a/app/views/tournaments/_selected.html.erb +++ b/app/views/tournaments/_selected.html.erb @@ -1,31 +1,15 @@ <%= form_for(@tournament) do |f| %> - <% if @tournament.errors.any? %> - <div id="error_explanation"> - <h2><%= pluralize(@tournament.errors.count, "error") %> prohibited this tournament from being saved:</h2> + <%= render "common/error_messages", :target => @tournament %> + <%= f.hidden_field(:game_id) %> - <ul> - <% @tournament.errors.full_messages.each do |msg| %> - <li><%= msg %></li> - <% end %> - </ul> - </div> - <% end %> - - <%# this is the dynamic script to output fields to the form %> - <% @chosen = Game.find(@game) %> - <% @chosen.attributes.each do |name, value| %> - <% if name == "id" %> + <% @tournament.attributes.each do |name, value| %> + <% if (name == "id") or (name =~ /.*_at$/) or (name == "game_id") %> <% next %> <% end %> - <% if name == "created_at" %> - <% break %> - <% end %> - <p> - <label for=<%= name %>><%= name.capitalize.gsub('_', ' ') %></label> - <br /> - <input type="text" id=<%= name %> value=<%= value %>> - </p> + <p> + <%= f.label name %><br> + <%= f.text_field name %> + </p> <% end %> - <%= f.submit %> -<% end %> +<% end %>
\ No newline at end of file diff --git a/app/views/tournaments/new.html.erb b/app/views/tournaments/new.html.erb index 3d6d142..1e80147 100644 --- a/app/views/tournaments/new.html.erb +++ b/app/views/tournaments/new.html.erb @@ -2,18 +2,18 @@ <h1>New Tournament</h1> -<%= select_tag 'tournament_id', options_for_select(["Select a Game Type"] + Game.all.collect {|game| game.name}), :onchange => 'populate()' %> <%= link_to 'Select', 'new?game=1', :class => "btn btn-success btn-xs" %> +<%= form_tag(new_tournament_path, method: "get") do %> + <%= select_tag('game', + options_from_collection_for_select(@games, 'id', 'name', @tournament.game.nil? || @tournament.game.id), + :prompt => "Select a Game Type") %> + <%= submit_tag("Select", :class => "btn btn-success btn-xs") %> +<% end %> - -<br /> <div id='ajax-form'> - <% if not @game.nil? %> + <% if not @tournament.game.nil? %> <%= render 'selected' %> <% end %> </div> -<br /><br /> - -<%= link_to 'Select', 'selected', :class => "btn btn-success btn-xs" %> <%= link_to 'Back', tournaments_path %> |