Migrate registration attributes to questions

This commit is contained in:
Stella 2014-11-09 18:25:36 +02:00
parent 08a47339a4
commit 59f2b636c5
9 changed files with 401 additions and 15 deletions

View file

@ -5,4 +5,6 @@ class Qanswer < ActiveRecord::Base
belongs_to :answer, dependent: :delete
has_and_belongs_to_many :registrations
validates :question, :answer, presence: true
end

View file

@ -7,8 +7,13 @@ class Question < ActiveRecord::Base
has_many :qanswers, dependent: :delete_all
has_many :answers, through: :qanswers, dependent: :delete_all
validates :title, presence: true
validates :answers, presence: true
validates :title, :question_type_id, presence: true
validate :existing_answers
accepts_nested_attributes_for :answers, allow_destroy: true
private
def existing_answers
errors.add(:base, 'The question must have answers') if self.answers.blank?
end
end

View file

@ -11,10 +11,8 @@ class Registration < ActiveRecord::Base
has_many :events_registrations
has_many :workshops, through: :events_registrations, source: :event
attr_accessible :user_id, :conference_id, :attending_social_events, :attending_with_partner,
:using_affiliated_lodging, :arrival, :departure, :user_attributes, :attended,
:other_dietary_choice, :dietary_choice_id, :handicapped_access_required,
:social_event_ids, :other_special_needs,
attr_accessible :user_id, :conference_id, :arrival, :departure, :user_attributes, :attended,
:other_dietary_choice, :dietary_choice_id, :social_event_ids, :other_special_needs,
:event_ids, :volunteer, :vchoice_ids, :qanswer_ids, :qanswers_attributes
accepts_nested_attributes_for :user