简体   繁体   中英

Rails form builder not working as expected

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| %> <%= form.fields_for :question do |builder| %>
with <%= form.fields_for :questions do |builder| %> <%= form.fields_for :questions do |builder| %>

solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM