Volunteer teams validation

This commit is contained in:
Petko Bordjukov 2016-07-06 11:24:20 +03:00
parent b40669aa76
commit 1ce5c2e35a
3 changed files with 11 additions and 1 deletions

View File

@ -12,6 +12,7 @@ class Volunteer < ActiveRecord::Base
validates :email, format: {with: /\A[^@]+@[^@]+\z/}, presence: true validates :email, format: {with: /\A[^@]+@[^@]+\z/}, presence: true
validates :phone, presence: true, format: {with: /\A[+\- \(\)0-9]+\z/} validates :phone, presence: true, format: {with: /\A[+\- \(\)0-9]+\z/}
validates :volunteer_teams, presence: true validates :volunteer_teams, presence: true
validate :volunteer_teams_belong_to_conference
phony_normalize :phone, default_country_code: 'BG' phony_normalize :phone, default_country_code: 'BG'
@ -35,4 +36,11 @@ class Volunteer < ActiveRecord::Base
def send_notification_to_volunteer def send_notification_to_volunteer
VolunteerMailer.volunteer_notification(self).deliver_later VolunteerMailer.volunteer_notification(self).deliver_later
end 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 end

View File

@ -120,6 +120,8 @@ bg:
attributes: attributes:
picture: picture:
invalid_content_type: "невалиден формат на снимката" invalid_content_type: "невалиден формат на снимката"
volunteer_teams:
invalid_volunteer_team: "невалиден екип от доброволци"
models: models:
volunteership: volunteership:
one: доброволец one: доброволец

View File

@ -10,7 +10,7 @@
= f.input :name, autofocus: true = f.input :name, autofocus: true
= f.input :email = f.input :email
= f.input :phone, input_html: {value: @volunteer.phone.try(:phony_formatted, format: :international)} = 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 :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_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) = f.input :tshirt_cut, collection: Volunteer::TSHIRT_CUTS, as: :radio_buttons, wrapper: :default, checked: (@volunteer.tshirt_cut.presence || :unisex)