I am using ryan bates nested_form gem to dynamically add some nested field to a form.
e.g.
<%= f.fields_for :phones do |phone_form| %>
<%= phone_form.text_field :phone_number %>
<% end %>
<%= f.link_to_add "Add a phone", :phones %></p>
Everything works, except TWO empty fields are added every time the link is clicked.
I placed a breakpoint on $('form a.add_nested_fields').live('click', function()
and see it is called twice...
I am using chrome on a mac
Look in your header. You'll see that this is in there twice:
<script src="/assets/nested_form.js?body=1" type="text/javascript"></script>
Just remove the second reference (perhaps in your application.html.erb) and it will work.
you may have nested form js files being loaded twice
For those having this issue using rails 4 / turbolinks and not finding nested_form.js included twice, try removing turbolinks from application.js. Once I did this and bounced the server this issue was resolved.
Credit here: https://github.com/ryanb/nested_form/issues/307
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With