I'm trying to build a nested form, but the nested form of question_fields isn't rendering in the browser. That form has a nested form called answers, also not rendering
Here's the nested form, _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'
Here's the _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
Here's the related Polls Controller, new and create actions
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
Any ideas on why this might not be rendering? Thanks in advance for the tips!!
Update, a new question
After creating the poll with its associated questions and answers, after querying the database, I see that that the foreign keys aren't persisted and the association is lost. Do I have to use hidden fields here somehow?