osem-fcy/app/models/registration_period.rb
2018-04-04 10:28:10 -07:00

32 lines
920 B
Ruby

# frozen_string_literal: true
class RegistrationPeriod < ApplicationRecord
belongs_to :conference
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
validates :start_date, :end_date, presence: true
validate :before_end_of_conference
validate :start_date_before_end_date
private
def before_end_of_conference
if conference&.end_date && start_date && (start_date > conference.end_date)
errors
.add(:start_date, "can't be after the conference end date (#{conference.end_date})")
end
if conference&.end_date && end_date && (end_date > conference.end_date)
errors
.add(:end_date, "can't be after the conference end date (#{conference.end_date})")
end
end
def start_date_before_end_date
if start_date && end_date && start_date > end_date
errors
.add(:start_date, "can't be after the end date")
end
end
end