diff options
author | tkimia <tkimia@purdue.edu> | 2014-04-28 22:01:00 -0400 |
---|---|---|
committer | tkimia <tkimia@purdue.edu> | 2014-04-28 22:01:00 -0400 |
commit | bc8be5e217279012cd4dc62e3fc2fe2bd9308b1c (patch) | |
tree | 00db3861642ba3ebfb51b85db92478019b62dad7 /app/models | |
parent | 927e21c067673a46c68e9ecfa191983ebb3874e7 (diff) |
bracket update works
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 |