diff --git a/app/models/bout.rb b/app/models/bout.rb index 32dcb0a..25ccdd6 100644 --- a/app/models/bout.rb +++ b/app/models/bout.rb @@ -1,15 +1,8 @@ class Bout - def assignBouts(tournament_id) - @round = 1 - until matchesByRound(@round, tournament_id).blank? do - @matches = matchesByRound(@round, tournament_id) - giveBout(@matches) - @round += 1 - end - end + - def matchesByRound(round, tournament_id) - @matches = Match.where(tournament_id: tournament_id, round: round) + def matchesByRound(round, matches) + @matches = matches.select {|m| m.round == round} return @matches end @@ -18,7 +11,21 @@ class Bout @matches.each_with_index do |m, i| bout = m.round * 1000 + i m.boutNumber = bout - m.save end + return @matches end + + def assignBouts(matches) + @round = 1 + until matchesByRound(@round, matches).blank? do + @matches = matchesByRound(@round, matches) + giveBout(@matches) + @round += 1 + end + return matches + end + + + + end \ No newline at end of file diff --git a/app/models/matchup.rb b/app/models/matchup.rb index aa763e9..69d23e7 100644 --- a/app/models/matchup.rb +++ b/app/models/matchup.rb @@ -1,5 +1,5 @@ class Matchup - attr_accessor :w1, :w2, :round, :weight_id + attr_accessor :w1, :w2, :round, :weight_id, :boutNumber # def w1 # end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 3702066..e196260 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -17,6 +17,7 @@ class Tournament < ActiveRecord::Base self.weights.sort_by{|x|[x.max]}.each do |weight| @upcomingMatches = weight.generateMatchups(@matches) end + @upcomingMatches = assignBouts(@upcomingMatches) return @upcomingMatches end @@ -40,9 +41,10 @@ class Tournament < ActiveRecord::Base - def assignBouts + def assignBouts(matches) @bouts = Bout.new - @bouts.assignBouts(self.id) + @matches = @bouts.assignBouts(matches) + return @matches end end diff --git a/app/views/static_pages/up_matches.html.erb b/app/views/static_pages/up_matches.html.erb index 17cc1af..52a5dff 100644 --- a/app/views/static_pages/up_matches.html.erb +++ b/app/views/static_pages/up_matches.html.erb @@ -18,7 +18,7 @@ <% @matches.each.map do |m| %>