diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index d46e6f3..78668ba 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -2,15 +2,15 @@ class StaticPagesController < ApplicationController before_filter :check_access, only: [:createCustomWeights,:generate_matches,:weigh_in] def tournaments - @tournaments = Tournament.all.includes(:user) + @tournaments = Tournament.all.includes(:user,:matches,:mats) end def up_matches if params[:tournament] @tournament = Tournament.find(params[:tournament]) end if @tournament - @matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10) - @mats = @tournament.mats + @matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10).includes(:wrestlers) + @mats = @tournament.mats.includes(:matches) if @tournament.matches.empty? redirect_to "/static_pages/noMatches?tournament=#{@tournament.id}" end diff --git a/app/models/match.rb b/app/models/match.rb index f596580..51cce5d 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -2,6 +2,7 @@ class Match < ActiveRecord::Base belongs_to :tournament belongs_to :weight belongs_to :mat + has_many :wrestlers, :through => :weight after_save do if self.finished == 1 @@ -30,6 +31,14 @@ class Match < ActiveRecord::Base end end + def wrestler1 + wrestlers.where(id: self.w1) + end + + def wrestler2 + wrestlers.where(id: self.w2) + end + def w1_name if self.w1 Wrestler.find(self.w1).name diff --git a/app/views/static_pages/up_matches.html.erb b/app/views/static_pages/up_matches.html.erb index 650dbb5..71eb650 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.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 %> + <%=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 %> <% end %> @@ -59,7 +59,7 @@ Round <%= m.round %> <%= m.bout_number %> <%= m.weight_max %> lbs - <%= m.w1_name %> vs. <%= m.w2_name %> + <%= m.wrestler1.name %> vs. <%= m.wrestler2.name %> <% end %>