Preassemble Nested Models

I have two models related to has_many. The parent model has accepts_nested_attributes_ for the child model.

According to all the tutorials and documents I can find, when using f.fields_for for a child model, it will only display fields if child models exist in it. It works, the part that doesn't work is creating empty children.

3.times { @post.comments.build }

It should, as I understand it, create 3 empty associated models and automatically display 3 sets of form fields.

It doesn’t matter if I use the .build method, Model.new method or something else, I can not get it to display any form fields.

I have to do something wrong, but I'm going to take the collective ingenious stackoverflow stack to show me: P

Refer to the default code .

thank

+3
source share
1 answer

Replace:

- f.fields_for :input_items do |item|

WITH

= f.fields_for :input_items do |item|
0
source

All Articles