2014-03-30 1 views
0

내가 레일 관계를 가지고사용자가 accepts_nested_attributes_for를 사용하여 정답을 선택할 수있게 하시겠습니까?

사용자가 퀴즈 # 편집 또는 퀴즈가 (라디오 버튼) 어떤 대답을 선택할 수있는 새로운 #에 이렇게 모델이 정답을 구조 인 것이다 어떻게
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 

?

답변

0

answers 테이블에서 'is_correct_answer'라는 추가 속성을 추가하면 하나의 조합에 대해서만 적용됩니다.

+0

이것은 추가 필요가 없으며 다른 방법으로 피할 수있는 추가 조인이라고 생각합니다. –

+0

추가 테이블 없이도 응답 테이블 자체에서 동일한 작업을 수행 할 수 있습니다. – emaillenin

관련 문제