2014-08-10 19:57:46 +03:00
|
|
|
class Conference < ActiveRecord::Base
|
|
|
|
validates :title, presence: true, uniqueness: true
|
|
|
|
validates :email, presence: true, format: {with: /\A[^@]+@[^@]+\z/}
|
|
|
|
validates :description, presence: true
|
|
|
|
validates :start_date, presence: true
|
|
|
|
validates :end_date, presence: true
|
|
|
|
validate :end_date_is_before_start_date
|
|
|
|
|
2014-08-10 20:30:37 +03:00
|
|
|
has_many :tracks
|
2014-08-10 21:17:06 +03:00
|
|
|
has_many :events, through: :tracks
|
2014-08-10 20:30:37 +03:00
|
|
|
|
2014-08-10 22:05:25 +03:00
|
|
|
scope :future, -> { where 'start_date >= ?', Date.today }
|
|
|
|
scope :current, -> { future.first || last }
|
|
|
|
|
2014-08-10 19:57:46 +03:00
|
|
|
private
|
|
|
|
|
|
|
|
def end_date_is_before_start_date
|
|
|
|
if start_date.present? and end_date.present? and start_date > end_date
|
|
|
|
errors.add(:end_date, :cannot_be_before_start_date)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|