允许用户使用accepts_nested_attributes_for选择正确答案?

时间:2014-03-30 12:10:18

标签: ruby-on-rails

我有轨道关系:

class Quiz < ActiveRecord::Base
  has_many :questions, dependent: :destroy
  accepts_nested_attributes_for :questions,
                            reject_if: proc { |a| a[:content].blank? },
                            allow_destroy: true
end

class Question < ActiveRecord::Base
  belongs_to :quiz
  has_many :answers, dependent: :destroy
  accepts_nested_attributes_for :answers,
                                reject_if: proc { |a| a[:content].blank? },
                                allow_destroy: true
end

class Answer < ActiveRecord::Base
  belongs_to :question
end

当用户处于Quiz#edit或Quiz#new时,如何构建模型,他们可以选择哪个答案(带单选按钮)是正确的答案?

1 个答案:

答案 0 :(得分:0)

answers表格中,添加名为&#39; is_correct_answer&#39;的其他属性。这只适用于一种组合。