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.
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.
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.