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

@ -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