Add registration_limit to conference model. Added the input for registration limit in the edit conference form. In the controller, if the limit has exceeded redirect to root_path with an alert. fix #761
This commit is contained in:
parent
2034c0f965
commit
28fbc518f3
12 changed files with 124 additions and 16 deletions
|
|
@ -65,6 +65,7 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
validates_uniqueness_of :short_title
|
||||
validates_format_of :short_title, with: /\A[a-zA-Z0-9_-]*\z/
|
||||
validates :registration_limit, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||
|
||||
# This validation is needed since a conference with a start date greater than the end date is not possible
|
||||
validate :valid_date_range?
|
||||
|
|
@ -536,6 +537,10 @@ class Conference < ActiveRecord::Base
|
|||
email_settings.conference_registration_dates_updated_body
|
||||
end
|
||||
|
||||
def registration_limit_exceeded?
|
||||
registration_limit > 0 && registrations.count >= registration_limit
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
after_create do
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ class Registration < ActiveRecord::Base
|
|||
validates :user, presence: true
|
||||
|
||||
validates_uniqueness_of :user_id, scope: :conference_id, message: 'already Registered!'
|
||||
validate :registration_limit_not_exceed, on: :create
|
||||
|
||||
after_create :set_week, :subscribe_to_conference, :send_registration_mail
|
||||
|
||||
|
|
@ -49,4 +50,10 @@ class Registration < ActiveRecord::Base
|
|||
self.week = created_at.strftime('%W')
|
||||
save!
|
||||
end
|
||||
|
||||
def registration_limit_not_exceed
|
||||
if self.conference.registration_limit>0 && self.conference.registrations(:reload).count >= self.conference.registration_limit
|
||||
errors.add(:base, 'Registration limit exceeded')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue