diff --git a/app/controllers/mats_controller.rb b/app/controllers/mats_controller.rb index b7c10e5..6969d7e 100644 --- a/app/controllers/mats_controller.rb +++ b/app/controllers/mats_controller.rb @@ -18,14 +18,13 @@ class MatsController < ApplicationController def new @mat = Mat.new if params[:tournament] - @tournament_field = params[:tournament] @tournament = Tournament.find(params[:tournament]) end end # GET /mats/1/edit def edit - @tournament_field = @mat.tournament_id + @tournament = Tournament.find(@mat.tournament_id) end # POST /mats @@ -82,17 +81,17 @@ class MatsController < ApplicationController end def check_access - if params[:tournament] - @tournament = Tournament.find(params[:tournament]) - elsif params[:mat] - @mat = Mat.new(mat_params) - @tournament = Tournament.find(@mat.tournament_id) - elsif @mat - @tournament = @mat.tournament - end - if current_user != @tournament.user - redirect_to '/static_pages/not_allowed' - end + if params[:tournament] + @tournament = Tournament.find(params[:tournament]) + elsif params[:mat] + @mat = Mat.new(mat_params) + @tournament = Tournament.find(@mat.tournament_id) + elsif @mat + @tournament = @mat.tournament + end + if current_user != @tournament.user + redirect_to '/static_pages/not_allowed' + end end diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 81c5039..163ac52 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -14,14 +14,12 @@ class SchoolsController < ApplicationController def new @school = School.new if params[:tournament] - @tournament_field = params[:tournament] @tournament = Tournament.find(params[:tournament]) end end # GET /schools/1/edit def edit - @tournament_field = @school.tournament_id @tournament = @school.tournament end @@ -79,17 +77,17 @@ class SchoolsController < ApplicationController end def check_access - if params[:tournament] - @tournament = Tournament.find(params[:tournament]) - elsif params[:school] - @school = School.new(school_params) - @tournament = Tournament.find(@school.tournament_id) - elsif @school - @tournament = @school.tournament - end - if current_user != @tournament.user - redirect_to '/static_pages/not_allowed' - end + if params[:tournament] + @tournament = Tournament.find(params[:tournament]) + elsif params[:school] + @school = School.new(school_params) + @tournament = Tournament.find(@school.tournament_id) + elsif @school + @tournament = @school.tournament + end + if current_user != @tournament.user + redirect_to '/static_pages/not_allowed' + end end end diff --git a/app/controllers/weights_controller.rb b/app/controllers/weights_controller.rb index cf7409e..90bb885 100644 --- a/app/controllers/weights_controller.rb +++ b/app/controllers/weights_controller.rb @@ -18,14 +18,12 @@ class WeightsController < ApplicationController def new @weight = Weight.new if params[:tournament] - @tournament_field = params[:tournament] @tournament = Tournament.find(params[:tournament]) end end # GET /weights/1/edit def edit - @tournament_field = @weight.tournament_id @tournament = @weight.tournament @mats = @tournament.mats end diff --git a/app/controllers/wrestlers_controller.rb b/app/controllers/wrestlers_controller.rb index f3f6273..9fd843b 100644 --- a/app/controllers/wrestlers_controller.rb +++ b/app/controllers/wrestlers_controller.rb @@ -14,7 +14,6 @@ class WrestlersController < ApplicationController def new @wrestler = Wrestler.new if params[:school] - @school_field = params[:school] @school = School.find(params[:school]) end if @school @@ -28,7 +27,6 @@ class WrestlersController < ApplicationController # GET /wrestlers/1/edit def edit - @school_field = @wrestler.school_id @school = @wrestler.school @tournament = @wrestler.tournament @weight = @wrestler.weight @@ -40,6 +38,7 @@ class WrestlersController < ApplicationController def create @wrestler = Wrestler.new(wrestler_params) @school = School.find(wrestler_params[:school_id]) + @weights = @school.tournament.weights respond_to do |format| if @wrestler.save format.html { redirect_to @school, notice: 'Wrestler was successfully created.' } diff --git a/app/views/mats/_form.html.erb b/app/views/mats/_form.html.erb index d3546cc..643b36f 100644 --- a/app/views/mats/_form.html.erb +++ b/app/views/mats/_form.html.erb @@ -16,8 +16,8 @@ <%= f.text_field :name %> -<% if @tournament_field %> - <%= f.hidden_field :tournament_id, :value => @tournament_field %> +<% if @tournament %> + <%= f.hidden_field :tournament_id, :value => @tournament.id %> <% end %>
diff --git a/app/views/schools/_form.html.erb b/app/views/schools/_form.html.erb index 7eaa610..89da353 100644 --- a/app/views/schools/_form.html.erb +++ b/app/views/schools/_form.html.erb @@ -17,7 +17,7 @@
<% if @school %> - <%= f.hidden_field :tournament_id, :value => @tournament_field %> + <%= f.hidden_field :tournament_id, :value => @tournament.id %> <% end %>
diff --git a/app/views/weights/_form.html.erb b/app/views/weights/_form.html.erb index f8e8c94..23fa52d 100644 --- a/app/views/weights/_form.html.erb +++ b/app/views/weights/_form.html.erb @@ -17,7 +17,7 @@ <% if @weight %> - <%= f.hidden_field :tournament_id, :value => @tournament_field %> + <%= f.hidden_field :tournament_id, :value => @tournament.id %> <% end %>
diff --git a/app/views/wrestlers/_form.html.erb b/app/views/wrestlers/_form.html.erb index 5256004..83c0c04 100644 --- a/app/views/wrestlers/_form.html.erb +++ b/app/views/wrestlers/_form.html.erb @@ -18,7 +18,7 @@
<% if @school %> - <%= f.hidden_field :school_id, :value => @school_field %> + <%= f.hidden_field :school_id, :value => @school.id %> <% else %>
<%= f.label 'School' %>