@ gem cocoon - how do i

9 views
Skip to first unread message

tom

unread,
Jun 10, 2019, 3:40:30 PM6/10/19
to Ruby on Rails: Talk
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 .... "


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


thank you

Ariel Juodziukynas

unread,
Jun 10, 2019, 3:46:04 PM6/10/19
to rubyonra...@googlegroups.com
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 :D 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)

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CADQqhMe6zJLnfg_PqM9G7qijxJbiEGcetoG2uifp8tvg2rJa2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ariel Juodziukynas

unread,
Jun 10, 2019, 3:47:21 PM6/10/19
to rubyonra...@googlegroups.com
If you want a blank book just do @user.books.build with no attributes
Reply all
Reply to author
Forward
0 new messages