clarion/app/models/conference.rb

31 lines
864 B
Ruby
Raw Normal View History

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-09-01 13:44:41 +03:00
translates :title, :description
2014-09-06 19:04:22 +03:00
has_many :tracks, -> { order('id asc') }
has_many :events, through: :tracks
has_many :candidate_speakers, through: :events
2014-10-14 18:27:28 +03:00
accepts_nested_attributes_for :tracks
2014-08-30 16:58:42 +03:00
scope :future, -> { where('start_date >= ?', Date.today).order('start_date ASC') }
def self.current
future.first || last
end
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