clarion/app/models/conference.rb

32 lines
1011 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 :start_date_is_before_end_date
2014-09-01 13:44:41 +03:00
translates :title, :description
2014-10-14 23:55:17 +03:00
has_many :tracks, -> { order('id asc') }, dependent: :destroy
has_many :events, through: :tracks
has_many :candidate_speakers, through: :events
2014-10-14 23:55:17 +03:00
has_many :halls, dependent: :destroy
2014-10-14 23:55:17 +03:00
accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, allow_destroy: true
2014-10-14 18:27:28 +03:00
2014-10-14 21:58:13 +03:00
before_save :close_all_other_calls_for_papers
private
2014-10-14 21:58:13 +03:00
def close_all_other_calls_for_papers
Conference.where.not(id: self.id).update_all call_for_papers_open: false
2014-10-14 21:58:13 +03:00
end
def start_date_is_before_end_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