diff --git a/app/models/registration.rb b/app/models/registration.rb index 5d2555f2..8281c9cb 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -27,6 +27,7 @@ class Registration < ActiveRecord::Base validates :user_id, uniqueness: { scope: :conference_id, message: 'already Registered!' } validate :registration_limit_not_exceed, on: :create validate :registration_to_events_only_if_present + validate :before_end_of_registration_period, on: :create after_create :set_week, :subscribe_to_conference, :send_registration_mail @@ -59,6 +60,12 @@ class Registration < ActiveRecord::Base end end + def before_end_of_registration_period + if conference && conference.registration_period && conference.registration_period.end_date && (Date.today > conference.registration_period.end_date) + errors.add(:created_at, "can't be after the registration period end date!") + end + end + def subscribe_to_conference Subscription.create(conference_id: conference.id, user_id: user.id) end