2014-03-26 11:09:39 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: predictions
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
2020-03-18 03:38:17 +00:00
|
|
|
# result :integer
|
2014-03-26 11:09:39 +00:00
|
|
|
# score1 :integer
|
|
|
|
# score2 :integer
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2020-03-18 03:38:17 +00:00
|
|
|
# match_id :integer
|
|
|
|
# user_id :integer
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_predictions_on_match_id (match_id)
|
|
|
|
# index_predictions_on_user_id (user_id)
|
2014-03-26 11:09:39 +00:00
|
|
|
#
|
|
|
|
|
2014-03-23 00:22:25 +00:00
|
|
|
class Prediction < ActiveRecord::Base
|
|
|
|
include Extra
|
|
|
|
|
2020-03-16 23:57:47 +00:00
|
|
|
#attr_protected :id, :created_at, :updated_at, :result
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
validates_presence_of :match, :user
|
2018-02-11 23:15:38 +00:00
|
|
|
validates_inclusion_of :score1, :in => 0..99, :message => "Invalid score"
|
|
|
|
validates_inclusion_of :score2, :in => 0..99, :message => "Invalid score"
|
2014-03-23 00:22:25 +00:00
|
|
|
validates_uniqueness_of :match_id, :scope => :user_id
|
|
|
|
|
2020-03-16 20:57:41 +00:00
|
|
|
scope :with_contest, -> { include({:match => :contest}) }
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
belongs_to :match
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
def can_create? cuser
|
|
|
|
cuser and match.match_time.future? and !match.score1 and !match.score2 and !cuser.predictions.exists?(:match_id => match.id)
|
|
|
|
end
|
2020-03-18 03:38:17 +00:00
|
|
|
|
|
|
|
def self.params(params, cuser)
|
|
|
|
params.require(:prediction).permit(:result, :score1, :score2, :match_id, :user_id)
|
|
|
|
end
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|