ネストされたフォームを作成しようとしていますが、ネストされたフォームの question_fields がブラウザーでレンダリングされません。そのフォームには、回答と呼ばれるネストされたフォームがあり、レンダリングされません
ネストされたフォーム _createpoll.html.haml は次のとおりです。
= form_for Poll.new, :class=>'create-poll-form', :remote => true do |f|
= f.text_field :title, :autofocus => true, :placeholder => "Poll Title"
= f.text_field :description, :placeholder => 'Description'
/ Required accepts_nested_attributes_for :questions in the polls model.
= f.fields_for :questions do |builder|
= render "questions/question_fields", :f => builder
= f.submit "Create Poll", :class => 'btn btn-danger'
_questions_fields.html.haml は次のとおりです。
%p
= f.label :content, "Question"
= f.text_area :content
= f.check_box :_destroy
= f.label :_destroy, "Remove Question"
%p
= f.fields_for :answers do |builder|
= render "answers/answer_fields", :f => builder
関連する Polls Controller、new および create アクションは次のとおりです。
def create
@poll = Poll.create(params[:poll])
end
def new
@poll = Poll.new
1.times do
question = @poll.questions.build
2.times {question.answers.build}
end
end
これがレンダリングされない理由についてのアイデアはありますか? ヒントを事前にありがとう!!
更新、新しい質問
関連する質問と回答を含む投票を作成した後、データベースにクエリを実行した後、外部キーが保持されておらず、関連付けが失われていることがわかりました。ここで何らかの方法で非表示フィールドを使用する必要がありますか?