From 347e339f7c8327b37d8a416073dc12fc3a78c895 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 13:10:09 -0400 Subject: fix the Tournaments#new form getting submitted --- app/controllers/tournaments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 62d32b1..5eba07c 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -198,7 +198,7 @@ class TournamentsController < ApplicationController end def tournament_stage_params(i) - params.require(:tournament).require(i.to_sym).permit(:scheduling_method, :seeding_method) + params.require(:tournament).require(:stages).require(i.to_s).permit(:scheduling_method, :seeding_method) end def is_owner?(object) -- cgit v1.2.3-2-g168b From a7a68011785381c3680d81e0eaf29964f0007fe1 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 13:10:42 -0400 Subject: touch up the tournaments form --- app/controllers/tournaments_controller.rb | 1 + app/views/tournaments/_form.html.erb | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 5eba07c..e115f18 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -171,6 +171,7 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_attribute_params + params[:num_stages] ||= 1 if params[:tournament] p = params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method) if p[:game_id] diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index b8d6fc1..95bb7c7 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -49,7 +49,7 @@
Settings - <%= fields_for "tournament[settings]", @tournament.settings do |setting_fields| %> + <%= f.fields_for :settings do |setting_fields| %> <% (@tournament.settings.empty? ? @tournament.game.settings : @tournament.settings).each do |setting| %>

<% name = setting.name.parameterize.underscore %> <%= setting_fields.label name %> @@ -81,20 +81,19 @@ <% end %>

-
Stages + <%= f.fields_for :stages do |stages_fields| %>
Stages - + <% for i in 1..(params[:num_stages].to_i) do %> - <%= fields_for "tournament[stages][#{i}]", @tournament.stages[i] do |stage_fields| %> -
Stage <%= i %> + <%= stages_fields.fields_for i.to_s do |stage_fields| %>
Stage <%= i %> <%= stage_fields.label :scheduling_method %> <%= stage_fields.select(:scheduling_method, @tournament.scheduling_methods.map{|method| [method.humanize, method]}) %> <%= stage_fields.label :seeding_method %> <%= stage_fields.select(:seeding_method, @tournament.seeding_methods.map{|method| [method.humanize, method]}) %> -
- <% end %> +
<% end %> <% end %> -
+
<% end %> + <%= f.submit %> <%# render 'stages' %> -- cgit v1.2.3-2-g168b From 751ae75e4b790edfbce2cd2340d5d04b98433405 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 13:11:18 -0400 Subject: TournamentsController: fix gross hack --- app/controllers/tournaments_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'app') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index e115f18..fdb80aa 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -15,8 +15,7 @@ class TournamentsController < ApplicationController when 0 render action: 'show' when 1 - #redirect_to tournament_matches_page(@tournament) - redirect_to "/tournaments/" + @tournament.id.to_s + "/matches" + redirect_to tournament_matches_path(@tournament) when 2 redirect_to tournaments_page end -- cgit v1.2.3-2-g168b From eacf4fcc2a45142cd865795f35d65341dfe665ad Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 13:12:40 -0400 Subject: TournamentsController: better error messages --- app/controllers/tournaments_controller.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index fdb80aa..e5cfb81 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -50,11 +50,20 @@ class TournamentsController < ApplicationController ok &= @tournament.update(tournament_setting_params) ok &= @tournament.hosts.push(current_user) for i in 1..(params[:num_stages].to_i) do - ok &= @tournament.stages.create(tournament_stage_params(i)) + begin + ok &= @tournament.stages.create(tournament_stage_params(i)) + rescue ActionController::ParameterMissing => e + ok = false + @tournament.errors.add("stages[#{i}]", "Stage #{i} not set") + end end end - rescue + rescue ActiveRecord::RecordNotUnique => e + ok = false + @tournament.errors.add(:name, "must be unique") + rescue => e ok = false + @tournament.errors.add(:exception, "Unknown error: ``#{e.class.name}'' -- #{e.inspect} -- #{e.methods - Object.new.methods}") end respond_to do |format| if ok -- cgit v1.2.3-2-g168b From 9a8d6814511ce257241a03b5763430294ed3e381 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 13:25:18 -0400 Subject: ran ./generate.sh --- app/controllers/games_controller.rb | 2 +- app/controllers/tournaments_controller.rb | 2 +- app/views/games/_form.html.erb | 8 -------- app/views/games/index.html.erb | 4 ---- app/views/games/index.json.jbuilder | 2 +- app/views/games/show.html.erb | 10 ---------- app/views/games/show.json.jbuilder | 2 +- app/views/tournaments/_form.html.erb | 8 -------- app/views/tournaments/index.html.erb | 4 ---- app/views/tournaments/index.json.jbuilder | 2 +- app/views/tournaments/show.html.erb | 10 ---------- app/views/tournaments/show.json.jbuilder | 2 +- 12 files changed, 6 insertions(+), 50 deletions(-) (limited to 'app') diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 76a6296..55d16a0 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -69,6 +69,6 @@ class GamesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def game_params - params.require(:game).permit(:parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method) + params.require(:game).permit(:parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :sampling_method, :scoring_method) end end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 64ab155..1b84f82 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -69,6 +69,6 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method) + params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :sampling_method, :scoring_method) end end diff --git a/app/views/games/_form.html.erb b/app/views/games/_form.html.erb index b1db0b3..e7def85 100644 --- a/app/views/games/_form.html.erb +++ b/app/views/games/_form.html.erb @@ -35,14 +35,6 @@ <%= f.label :max_teams_per_match %>
<%= f.number_field :max_teams_per_match %> -
- <%= f.label :set_rounds %>
- <%= f.number_field :set_rounds %> -
-
- <%= f.label :randomized_teams %>
- <%= f.check_box :randomized_teams %> -
<%= f.label :sampling_method %>
<%= f.text_field :sampling_method %> diff --git a/app/views/games/index.html.erb b/app/views/games/index.html.erb index 207a0ba..8c316de 100644 --- a/app/views/games/index.html.erb +++ b/app/views/games/index.html.erb @@ -9,8 +9,6 @@ Max players per team Min teams per match Max teams per match - Set rounds - Randomized teams Sampling method Scoring method @@ -28,8 +26,6 @@ <%= game.max_players_per_team %> <%= game.min_teams_per_match %> <%= game.max_teams_per_match %> - <%= game.set_rounds %> - <%= game.randomized_teams %> <%= game.sampling_method %> <%= game.scoring_method %> <%= link_to 'Show', game %> diff --git a/app/views/games/index.json.jbuilder b/app/views/games/index.json.jbuilder index 7964f2c..0e9769b 100644 --- a/app/views/games/index.json.jbuilder +++ b/app/views/games/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@games) do |game| - json.extract! game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method + json.extract! game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :sampling_method, :scoring_method json.url game_url(game, format: :json) end diff --git a/app/views/games/show.html.erb b/app/views/games/show.html.erb index 6bca111..f132d9a 100644 --- a/app/views/games/show.html.erb +++ b/app/views/games/show.html.erb @@ -30,16 +30,6 @@ <%= @game.max_teams_per_match %>

-

- Set rounds: - <%= @game.set_rounds %> -

- -

- Randomized teams: - <%= @game.randomized_teams %> -

-

Sampling method: <%= @game.sampling_method %> diff --git a/app/views/games/show.json.jbuilder b/app/views/games/show.json.jbuilder index c5fb4ed..981c31e 100644 --- a/app/views/games/show.json.jbuilder +++ b/app/views/games/show.json.jbuilder @@ -1 +1 @@ -json.extract! @game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method, :created_at, :updated_at +json.extract! @game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :sampling_method, :scoring_method, :created_at, :updated_at diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 7127d38..be5cf56 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -39,14 +39,6 @@ <%= f.label :max_teams_per_match %>
<%= f.number_field :max_teams_per_match %>

-
- <%= f.label :set_rounds %>
- <%= f.number_field :set_rounds %> -
-
- <%= f.label :randomized_teams %>
- <%= f.check_box :randomized_teams %> -
<%= f.label :sampling_method %>
<%= f.text_field :sampling_method %> diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index c2b5a2b..1dddd5d 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -10,8 +10,6 @@ Max players per team Min teams per match Max teams per match - Set rounds - Randomized teams Sampling method Scoring method @@ -30,8 +28,6 @@ <%= tournament.max_players_per_team %> <%= tournament.min_teams_per_match %> <%= tournament.max_teams_per_match %> - <%= tournament.set_rounds %> - <%= tournament.randomized_teams %> <%= tournament.sampling_method %> <%= tournament.scoring_method %> <%= link_to 'Show', tournament %> diff --git a/app/views/tournaments/index.json.jbuilder b/app/views/tournaments/index.json.jbuilder index bd86e04..c6b9e68 100644 --- a/app/views/tournaments/index.json.jbuilder +++ b/app/views/tournaments/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@tournaments) do |tournament| - json.extract! tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method + json.extract! tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :sampling_method, :scoring_method json.url tournament_url(tournament, format: :json) end diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index f91e11e..f407295 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -35,16 +35,6 @@ <%= @tournament.max_teams_per_match %>

-

- Set rounds: - <%= @tournament.set_rounds %> -

- -

- Randomized teams: - <%= @tournament.randomized_teams %> -

-

Sampling method: <%= @tournament.sampling_method %> diff --git a/app/views/tournaments/show.json.jbuilder b/app/views/tournaments/show.json.jbuilder index ff82412..afc5814 100644 --- a/app/views/tournaments/show.json.jbuilder +++ b/app/views/tournaments/show.json.jbuilder @@ -1 +1 @@ -json.extract! @tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method, :created_at, :updated_at +json.extract! @tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :sampling_method, :scoring_method, :created_at, :updated_at -- cgit v1.2.3-2-g168b