summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authortkimia <tkimia@purdue.edu>2014-04-28 22:01:00 -0400
committertkimia <tkimia@purdue.edu>2014-04-28 22:01:00 -0400
commitbc8be5e217279012cd4dc62e3fc2fe2bd9308b1c (patch)
tree00db3861642ba3ebfb51b85db92478019b62dad7 /app/models
parent927e21c067673a46c68e9ecfa191983ebb3874e7 (diff)
bracket update works
Diffstat (limited to 'app/models')
-rw-r--r--app/models/bracket.rb14
-rw-r--r--app/models/bracket_match.rb4
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