Migrate registration attributes to questions
This commit is contained in:
parent
08a47339a4
commit
59f2b636c5
9 changed files with 401 additions and 15 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue