blob: fc3e10ea9c8faeb53b0fcd8c65a823a647c39198 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
class Bracket < ActiveRecord::Base
belongs_to :user
belongs_to :tournament
has_many :bracket_matches
def create_matches
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
|