From cce30bdf3a9440a2b5698621116df7aceb40f571 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Mon, 11 Jan 2016 16:48:08 +0000 Subject: [PATCH] Fixed mat assignment when matches are finished --- app/models/mat.rb | 2 +- app/models/match.rb | 4 +++- app/models/tournament.rb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) 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