osem-fcy/app/models/call_for_booth.rb
2017-06-26 22:15:49 +03:00

28 lines
903 B
Ruby

class CallForBooth < ActiveRecord::Base
belongs_to :conference
has_many :booths
validates :start_date, :end_date, :booth_limit, presence: true
validate :before_end_of_conference
validate :start_date_before_end_date
def remaining_days(date = Date.today)
end_date - date > 0 ? (end_date - date) : 0
end
private
def before_end_of_conference
errors
.add(:start_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && start_date && (start_date > conference.end_date)
errors
.add(:end_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && end_date && (end_date > conference.end_date)
end
def start_date_before_end_date
errors
.add(:start_date, "can't be after the end date") if start_date && end_date && start_date > end_date
end
end