ryanb / nested_form

Rails plugin to conveniently handle multiple models in a single form.
MIT License
1.79k stars 505 forks source link

Multiple fields being created for Rails 4 #284

Closed rmatesic closed 10 years ago

rmatesic commented 10 years ago

I am having a weird issue with rails 4. I have implemented my view to have the following. Sometimes when I click add a new address, it only adds 1 field. But other times when I click it adds multiple fields. And when it has added multiple fields and clicked to remove the object, it triggers the confirm on the button multiple times. Just wondering if anyone else has experienced this. Have I implemented it wrong, or is it simply a bug in rails 4.

#customer_addresses
  = f.fields_for :customer_addresses do |builder|
    = render partial: 'customer_addresses', locals: { f: builder }

form-section
  .row-fluid
    = f.link_to_add "Add a new address", :customer_addresses, :data => { :target => "#customer_addresses" }, class: 'btn btn-success btn-mini', confirm: "Are you sure?"
rmatesic commented 10 years ago

Figured it out over the weekend. Forgot to add :_destroy, to my permitted params. Therefore the controller was ignoring it and not removing my record.