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| %>