From 364ee21e3f5b6c5b5912879c5cb8d47fbf75017a Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Mon, 2 Nov 2015 11:14:03 -0500 Subject: [PATCH] trying to speed up brackets page --- app/controllers/static_pages_controller.rb | 6 +++--- app/models/match.rb | 4 ++-- app/views/static_pages/up_matches.html.erb | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 78668ba..a0ea95e 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -39,10 +39,10 @@ class StaticPagesController < ApplicationController def brackets if params[:weight] - @weight = Weight.find(params[:weight]) + @weight = Weight.find(params[:weight]).includes(:matches,:wrestlers) @tournament = Tournament.find(@weight.tournament_id) - @matches = @tournament.matches.select{|m| m.weight_id == @weight.id} - @wrestlers = Wrestler.where(weight_id: @weight.id).includes(:weight,:school) + @matches = @weight.matches + @wrestlers = @weight.wrestlers.includes(:school) if @matches.empty? or @wrestlers.empty? redirect_to "/static_pages/noMatches?tournament=#{@tournament.id}" else diff --git a/app/models/match.rb b/app/models/match.rb index bd44724..4d6d2bd 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -41,7 +41,7 @@ class Match < ActiveRecord::Base def w1_name if self.w1 - Wrestler.find(self.w1).name + wrestler1.name else self.loser1_name end @@ -49,7 +49,7 @@ class Match < ActiveRecord::Base def w2_name if self.w2 - Wrestler.find(self.w2).name + wrestler2.name else self.loser2_name end diff --git a/app/views/static_pages/up_matches.html.erb b/app/views/static_pages/up_matches.html.erb index 71eb650..650dbb5 100644 --- a/app/views/static_pages/up_matches.html.erb +++ b/app/views/static_pages/up_matches.html.erb @@ -30,10 +30,10 @@ <% @mats.each.map do |m| %> <%= m.name %> - <%=m.unfinishedMatches.first.bout_number%>
<%= m.unfinishedMatches.first.wrestler1.name %> vs. <%= m.unfinishedMatches.first.wrestler2.name %> - <%=m.unfinishedMatches.second.bout_number%>
<%= m.unfinishedMatches.second.wrestler1.name %> vs. <%= m.unfinishedMatches.second.wrestler2.name %> - <%=m.unfinishedMatches.third.bout_number%>
<%= m.unfinishedMatches.third.wrestler1.name %> vs. <%= m.unfinishedMatches.third.wrestler2.name %> - <%=m.unfinishedMatches.fourth.bout_number%>
<%= m.unfinishedMatches.fourth.wrestler1.name %> vs. <%= m.unfinishedMatches.fourth.wrestler2.name %> + <%=m.unfinishedMatches.first.bout_number%>
<%= m.unfinishedMatches.first.w1_name %> vs. <%= m.unfinishedMatches.first.w2_name %> + <%=m.unfinishedMatches.second.bout_number%>
<%= m.unfinishedMatches.second.w1_name %> vs. <%= m.unfinishedMatches.second.w2_name %> + <%=m.unfinishedMatches.third.bout_number%>
<%= m.unfinishedMatches.third.w1_name %> vs. <%= m.unfinishedMatches.third.w2_name %> + <%=m.unfinishedMatches.fourth.bout_number%>
<%= m.unfinishedMatches.fourth.w1_name %> vs. <%= m.unfinishedMatches.fourth.w2_name %> <% end %> @@ -59,7 +59,7 @@ Round <%= m.round %> <%= m.bout_number %> <%= m.weight_max %> lbs - <%= m.wrestler1.name %> vs. <%= m.wrestler2.name %> + <%= m.w1_name %> vs. <%= m.w2_name %> <% end %>