0
調査では、多くの答えを持っている多くの質問があります。SurveysControllerで未定義方法
class Survey < ActiveRecord::Base
has_many :questions, :dependent => :destroy
accepts_nested_attributes_for :questions, :reject_if => -> (a) {a[:content].blank? }, :allow_destroy => true
end
class Question < ActiveRecord::Base
belongs_to :survey
has_many :answers, :dependent => :destroy
accepts_nested_attributes_for :answers, :reject_if => -> (a) {a[:content].blank? }, :allow_destroy => true
end
class Answer < ActiveRecord::Base
belongs_to :question
end
を、私はこれを実行します。
def show
@survey = Survey.find(params[:id])
@questions = @survey.questions
@answers = @questions.answers
end
を、私はエラーを取得:
undefined method `answers' for #<Question::ActiveRecord_Associations_CollectionProxy:0x007f7f68af6948>
と、この行のレールが問題点として指摘しています。@answers = @questions.answers
なぜですか?
を使用することです。ありがとうございました! –