Add validations for registration_period
This commit is contained in:
parent
68cc4a73d9
commit
f567187d45
6 changed files with 122 additions and 32 deletions
|
|
@ -1,5 +1,22 @@
|
|||
class RegistrationPeriod < ActiveRecord::Base
|
||||
validates :start_date, :end_date, presence: true
|
||||
|
||||
belongs_to :conference
|
||||
|
||||
validates :start_date, :end_date, presence: true
|
||||
validate :before_end_of_conference
|
||||
validate :start_date_before_end_date
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue