Make sure the event type belongs to the parent conference
This commit is contained in:
parent
bfb8c7e53d
commit
0284c8ec7e
|
@ -22,11 +22,12 @@ class Event < ActiveRecord::Base
|
|||
validates :description, presence: true
|
||||
validates :agreement, acceptance: true
|
||||
validates :track, presence: true
|
||||
validate :track_belongs_to_the_selected_conference
|
||||
validates :language, inclusion: {in: I18n.available_locales.map(&:to_s)}, presence: true
|
||||
validates :event_type, presence: true
|
||||
validates :length, presence: true, numericality: {only_integer: true}
|
||||
validate :length_is_within_the_permitted_interval
|
||||
validate :track_belongs_to_the_selected_conference
|
||||
validate :event_type_belongs_to_the_selected_conference
|
||||
|
||||
delegate :status, to: :proposition
|
||||
|
||||
|
@ -76,6 +77,12 @@ class Event < ActiveRecord::Base
|
|||
|
||||
private
|
||||
|
||||
def event_type_belongs_to_the_selected_conference
|
||||
unless conference.present? and conference.event_types.include?(event_type)
|
||||
errors.add :event_type, :must_be_a_valid_event_type
|
||||
end
|
||||
end
|
||||
|
||||
def track_belongs_to_the_selected_conference
|
||||
unless conference.present? and conference.tracks.include?(track)
|
||||
errors.add :track, :must_be_a_valid_track
|
||||
|
@ -83,8 +90,10 @@ class Event < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def length_is_within_the_permitted_interval
|
||||
unless length >= event_type.minimum_length and length <= event_type.maximum_length
|
||||
errors.add :length, :must_be_between, minimum: event_type.minimum_length, maximum: event_type.maximum_length
|
||||
if event_type.present?
|
||||
unless length >= event_type.minimum_length and length <= event_type.maximum_length
|
||||
errors.add :length, :must_be_between, minimum: event_type.minimum_length, maximum: event_type.maximum_length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- content_for :title
|
||||
= t('.edit', event_type: @event.event_type.name.mb_chars.downcase, event_title: @event.title)
|
||||
= t('.edit', event_type: @event.event_type.try(:name).try(:mb_chars).try(:downcase), event_title: @event.title)
|
||||
|
||||
.row
|
||||
.col-xs-12
|
||||
|
@ -11,9 +11,9 @@
|
|||
= simple_nested_form_for [:management, @conference, @event], wrapper: :horizontal_form, html: { class: 'form-horizontal' } do |f|
|
||||
= f.input :title
|
||||
= f.input :subtitle
|
||||
= f.association :event_type
|
||||
= f.association :event_type, collection: current_conference.event_types
|
||||
= f.association :track, collection: current_conference.tracks.map { |track| [track.name, track.id, {title: track.description}] }
|
||||
= f.input :length, hint: t('simple_form.hints.event.length', type: @event.event_type.name.mb_chars.downcase, min: @event.event_type.minimum_length, max: @event.event_type.maximum_length)
|
||||
= f.input :length
|
||||
= f.input :language, collection: locale_collection, include_blank: false
|
||||
= f.input :abstract
|
||||
= f.input :description
|
||||
|
|
Loading…
Reference in New Issue