Reputation: 91
So what I have is a report model and an entries model. The report has many entries and entries belong to the report. What I am wanting to do is be able to click a button on the show page of the report and add new entries. Is there a way of doing this? A non-ajax solution is fine.
Upvotes: 0
Views: 91
Reputation: 36860
Cocoon
is an excellent gem for this.
It gives you a Remove
button for each entry and an Add
button to add as many entries as you want. Add accepts_nested_attributes_for :entries
to your Report model. You need to put the entries form in their own partial but that's not a hardship, and cocoon automatically creates the show/hide jquery for you. Be sure to include and whitelist the entries' id
column as a hidden field otherwise you can end up with duplicate entries, and you also need to whitelist _delete
(that's underscore + delete) so that the entries can be deleted by rails when required.
Upvotes: 1