@ gem cocoon - how do i

HI, i am baffled on how to make the first set of nested fields visible.
currently, it all works, but even just in order to display the 1st set of fields, i have to click "add … "

how do i assign values to the object in the controller to the first set ?

thank you

Let’s say you have a user that has many books, if you want to hace some book prefilled just do

@user.books.build(title: something, year: someyear)

As long as you don’t reload the relationship, the books will be on the user (just not persisted) and fields_for :books will iterate over them

You can give a try to my gem for dynamic nested fields, I’d really appreciate it :smiley: https://rubygems.org/gems/vanilla_nested (it’s similar to cocoon but weight less than 10%, and it has no dependencies like cocoon that adds a lot of gems and depends on jquery)

If you want a blank book just do @user.books.build with no attributes