I am trying to reproduce the functionality as demonstrated in railscast episode 196 Nested Model Form which is quite old.
The problem i am facing is that, Rails is currently displaying only one instance of question and choices instead of 3.
In my app the relevant models are paper, question and choice.
Relevant code chunks:
app/controllers/papers_controller.rb
def new
@paper = Paper.new
3.times do
question = @paper.questions.build
3.times { question.choices.build }
end
end
app/views/papers/_form too long to be posted here
app/views/papers/_question_fields
app/views/papers/_choice_fields
For complete app code see github repo.
The line causing the problem was in app/views/papers/_form
.
Replacing <%= form.fields_for :question do |builder| %>
with <%= form.fields_for :questions do |builder| %>
solved the issue.