diff --git a/app/models/mat.rb b/app/models/mat.rb index 6b56c84..e699758 100644 --- a/app/models/mat.rb +++ b/app/models/mat.rb @@ -21,7 +21,7 @@ class Mat < ActiveRecord::Base end def assignNextMatch - t_matches = tournament.matches.select{|m| m.mat_id == nil} + t_matches = tournament.matches.select{|m| m.mat_id == nil && m.finished != 1} if t_matches.size > 0 match = t_matches.sort_by{|m| m.bout_number}.first match.mat_id = self.id diff --git a/app/models/match.rb b/app/models/match.rb index 95a37c4..11c9823 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -54,7 +54,9 @@ class Match < ActiveRecord::Base @w2 = wrestler2 @w1.advanceInBracket @w2.advanceInBracket - self.mat.assignNextMatch + if self.mat + self.mat.assignNextMatch + end end end if Rails.env.production? diff --git a/app/models/tournament.rb b/app/models/tournament.rb index b1c7933..e2a983a 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -79,7 +79,7 @@ class Tournament < ActiveRecord::Base end def resetMats - matchesToReset = matches.select{|m| m.finished != 1 && m.mat_id != nil} + matchesToReset = matches.select{|m| m.mat_id != nil} # matchesToReset.update_all( {:mat_id => nil } ) matchesToReset.each do |m| m.mat_id = nil