diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/bracket.rb | 14 | ||||
-rw-r--r-- | app/models/bracket_match.rb | 4 |
2 files changed, 16 insertions, 2 deletions
diff --git a/app/models/bracket.rb b/app/models/bracket.rb index acd33ca..fc3e10e 100644 --- a/app/models/bracket.rb +++ b/app/models/bracket.rb @@ -4,8 +4,20 @@ class Bracket < ActiveRecord::Base has_many :bracket_matches def create_matches - tournament.stages.first.matches.each do |m| + tournament.stages.order(:id).first.matches.order(:id).each do |m| bracket_matches.create(match: m) end end + + + def predict_winners(predictions) + require 'pp' + puts("<"*80) + pp predictions + puts(">"*80) + (0..bracket_matches.count-1).each do |i| + bracket_matches.order(:match_id)[i].update(predicted_winner: Team.find(predictions[(i+1).to_s])); + end + return true + end end diff --git a/app/models/bracket_match.rb b/app/models/bracket_match.rb index 823bc40..f9a11f0 100644 --- a/app/models/bracket_match.rb +++ b/app/models/bracket_match.rb @@ -1,5 +1,7 @@ class BracketMatch < ActiveRecord::Base belongs_to :bracket belongs_to :match - belongs_to :predicted_winner + belongs_to :predicted_winner, class_name: "Team" + + end |