diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index 916da12..c73897f 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -11,11 +11,11 @@ class MatchesController < ApplicationController
# GET /matches/1/edit
def edit
if params[:match]
- @match = Match.find (params[:match])
+ @match = Match.where(:id => params[:match]).includes(:wrestlers).first
end
if @match
- @w1 = Wrestler.find(@match.w1)
- @w2 = Wrestler.find(@match.w2)
+ @w1 = @match.wrestler1
+ @w2 = @match.wrestler2
end
end
diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb
index 9a4d942..f1e096b 100644
--- a/app/controllers/schools_controller.rb
+++ b/app/controllers/schools_controller.rb
@@ -22,7 +22,7 @@ class SchoolsController < ApplicationController
# GET /schools/1/edit
def edit
@tournament_field = @school.tournament_id
- @tournament = Tournament.find(@school.tournament_id)
+ @tournament = @school.tournament
end
# POST /schools
@@ -70,7 +70,7 @@ class SchoolsController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_school
- @school = School.find(params[:id])
+ @school = School.where(:id => params[:id]).includes(:tournament,:wrestlers).first
end
# Never trust parameters from the scary internet, only allow the white list through.
diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb
index 6bc5935..a6a3e6d 100644
--- a/app/controllers/static_pages_controller.rb
+++ b/app/controllers/static_pages_controller.rb
@@ -97,18 +97,20 @@ class StaticPagesController < ApplicationController
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
end
if params[:tournament]
- @tournament = Tournament.find(params[:tournament])
+ @tournament = Tournament.where(:id => params[:tournament]).includes(:weights).first
@tournament_id = @tournament.id
@tournament_name = @tournament.name
end
if @tournament
- @weights = Weight.where(tournament_id: @tournament.id)
+ @weights = @tournament.weights
@weights = @weights.sort_by{|x|[x.max]}
end
if params[:weight]
- @weight = Weight.find(params[:weight])
- @tournament_id = @weight.tournament_id
- @tournament_name = Tournament.find(@tournament_id).name
+ @weight = Weight.where(:id => params[:weight]).includes(:tournament,:wrestlers).first
+ @tournament_id = @weight.tournament.id
+ @tournament_name = @weight.tournament.name
+ @tournament = @weight.tournament
+ @weights = @tournament.weights
end
if @weight
@wrestlers = @weight.wrestlers
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb
index 08b146f..45ebfe2 100644
--- a/app/controllers/tournaments_controller.rb
+++ b/app/controllers/tournaments_controller.rb
@@ -71,7 +71,7 @@ class TournamentsController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_tournament
- @tournament = Tournament.find(params[:id])
+ @tournament = Tournament.where(:id => params[:id]).includes(:schools,:weights,:mats).first
end
# Never trust parameters from the scary internet, only allow the white list through.
diff --git a/app/controllers/weights_controller.rb b/app/controllers/weights_controller.rb
index 513c83a..cf7409e 100644
--- a/app/controllers/weights_controller.rb
+++ b/app/controllers/weights_controller.rb
@@ -9,8 +9,8 @@ class WeightsController < ApplicationController
if params[:wrestler]
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
end
- @wrestlers = Wrestler.all
- @tournament = Tournament.find(@weight.tournament_id)
+ @wrestlers = @weight.wrestlers
+ @tournament = @weight.tournament
end
@@ -26,8 +26,8 @@ class WeightsController < ApplicationController
# GET /weights/1/edit
def edit
@tournament_field = @weight.tournament_id
- @mats = Mat.where(tournament_id: @weight.tournament.id)
- @tournament = Tournament.find(@weight.tournament_id)
+ @tournament = @weight.tournament
+ @mats = @tournament.mats
end
# POST /weights
@@ -52,7 +52,7 @@ class WeightsController < ApplicationController
# PATCH/PUT /weights/1
# PATCH/PUT /weights/1.json
def update
- @tournament = Tournament.find(@weight.tournament_id)
+ @tournament = @weight.tournament
if current_user != @tournament.user
redirect_to root_path
end
@@ -84,7 +84,7 @@ class WeightsController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_weight
- @weight = Weight.find(params[:id])
+ @weight = Weight.where(:id => params[:id]).includes(:tournament,:wrestlers).first
end
# Never trust parameters from the scary internet, only allow the white list through.
diff --git a/app/controllers/wrestlers_controller.rb b/app/controllers/wrestlers_controller.rb
index 4c0d227..06ad302 100644
--- a/app/controllers/wrestlers_controller.rb
+++ b/app/controllers/wrestlers_controller.rb
@@ -6,7 +6,7 @@ class WrestlersController < ApplicationController
# GET /wrestlers/1
# GET /wrestlers/1.json
def show
- @school = School.find(@wrestler.school_id)
+ @school = @wrestler.school
end
# GET /wrestlers/new
@@ -20,9 +20,7 @@ class WrestlersController < ApplicationController
@tournament = Tournament.find(@school.tournament_id)
end
if @tournament
- @weight = Weight.where(tournament_id: @tournament.id)
- else
- @weight = Weight.all
+ @weights = Weight.where(tournament_id: @tournament.id)
end
end
@@ -30,9 +28,10 @@ class WrestlersController < ApplicationController
# GET /wrestlers/1/edit
def edit
@school_field = @wrestler.school_id
- @school = School.find(@wrestler.school_id)
- @tournament = Tournament.find(@school.tournament_id)
- @weight = Weight.where(tournament_id: @tournament.id)
+ @school = @wrestler.school
+ @tournament = @wrestler.tournament
+ @weight = @wrestler.weight
+ @weights = @tournament.weights
end
# POST /wrestlers
@@ -54,7 +53,7 @@ class WrestlersController < ApplicationController
# PATCH/PUT /wrestlers/1
# PATCH/PUT /wrestlers/1.json
def update
- @school = School.find(@wrestler.school_id)
+ @school = @wrestler.school
respond_to do |format|
if @wrestler.update(wrestler_params)
format.html { redirect_to @school, notice: 'Wrestler was successfully updated.' }
@@ -69,7 +68,7 @@ class WrestlersController < ApplicationController
# DELETE /wrestlers/1
# DELETE /wrestlers/1.json
def destroy
- @school = School.find(@wrestler.school_id)
+ @school = @wrestler.school
@wrestler.destroy
respond_to do |format|
format.html { redirect_to @school }
@@ -80,7 +79,7 @@ class WrestlersController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_wrestler
- @wrestler = Wrestler.find(params[:id])
+ @wrestler = Wrestler.where(:id => params[:id]).includes(:tournament,:school,:weight).first
end
# Never trust parameters from the scary internet, only allow the white list through.
diff --git a/app/views/static_pages/weigh_in.html.erb b/app/views/static_pages/weigh_in.html.erb
index ca4ddb9..0ed5962 100644
--- a/app/views/static_pages/weigh_in.html.erb
+++ b/app/views/static_pages/weigh_in.html.erb
@@ -1,7 +1,7 @@
<%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %>
-<% if @tournament %>
+<% if params[:tournament] %>
<% @weights.each do |weight| %>
<%= link_to "#{weight.max}" , "/static_pages/weigh_in?weight=#{weight.id}" %>
diff --git a/app/views/wrestlers/_form.html.erb b/app/views/wrestlers/_form.html.erb
index fde20b0..9d7cf9a 100644
--- a/app/views/wrestlers/_form.html.erb
+++ b/app/views/wrestlers/_form.html.erb
@@ -21,12 +21,12 @@
<% else %>