Volunteer teams validation
This commit is contained in:
parent
b40669aa76
commit
1ce5c2e35a
|
@ -12,6 +12,7 @@ class Volunteer < ActiveRecord::Base
|
|||
validates :email, format: {with: /\A[^@]+@[^@]+\z/}, presence: true
|
||||
validates :phone, presence: true, format: {with: /\A[+\- \(\)0-9]+\z/}
|
||||
validates :volunteer_teams, presence: true
|
||||
validate :volunteer_teams_belong_to_conference
|
||||
|
||||
phony_normalize :phone, default_country_code: 'BG'
|
||||
|
||||
|
@ -35,4 +36,11 @@ class Volunteer < ActiveRecord::Base
|
|||
def send_notification_to_volunteer
|
||||
VolunteerMailer.volunteer_notification(self).deliver_later
|
||||
end
|
||||
|
||||
def volunteer_teams_belong_to_conference
|
||||
conference_volunteer_teams = conference.volunteer_teams
|
||||
unless volunteer_teams.all? { |team| conference_volunteer_teams.include? team }
|
||||
errors.add :volunteer_teams, :invalid_volunteer_team
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -120,6 +120,8 @@ bg:
|
|||
attributes:
|
||||
picture:
|
||||
invalid_content_type: "невалиден формат на снимката"
|
||||
volunteer_teams:
|
||||
invalid_volunteer_team: "невалиден екип от доброволци"
|
||||
models:
|
||||
volunteership:
|
||||
one: доброволец
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
= f.input :name, autofocus: true
|
||||
= f.input :email
|
||||
= f.input :phone, input_html: {value: @volunteer.phone.try(:phony_formatted, format: :international)}
|
||||
= f.association :volunteer_teams, as: :check_boxes, wrapper: :default
|
||||
= f.association :volunteer_teams, as: :check_boxes, wrapper: :default, collection: current_conference.volunteer_teams
|
||||
= f.input :language, as: :radio_buttons, collection: locale_collection, include_blank: false, wrapper: :default, checked: (@volunteer.language.presence || I18n.locale)
|
||||
= f.input :tshirt_size, collection: Volunteer::TSHIRT_SIZES, as: :radio_buttons, wrapper: :default, checked: (@volunteer.tshirt_size.presence || :m)
|
||||
= f.input :tshirt_cut, collection: Volunteer::TSHIRT_CUTS, as: :radio_buttons, wrapper: :default, checked: (@volunteer.tshirt_cut.presence || :unisex)
|
||||
|
|
Loading…
Reference in New Issue