diff --git a/app/models/volunteer.rb b/app/models/volunteer.rb index 320d1ea..321f359 100644 --- a/app/models/volunteer.rb +++ b/app/models/volunteer.rb @@ -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 diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 7223133..30f1d67 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -120,6 +120,8 @@ bg: attributes: picture: invalid_content_type: "невалиден формат на снимката" + volunteer_teams: + invalid_volunteer_team: "невалиден екип от доброволци" models: volunteership: one: доброволец diff --git a/lib/initfest/views/public/volunteers/_form.slim b/lib/initfest/views/public/volunteers/_form.slim index 8cdf55e..8104d33 100644 --- a/lib/initfest/views/public/volunteers/_form.slim +++ b/lib/initfest/views/public/volunteers/_form.slim @@ -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)