Search code examples
ruby-on-railsruby-on-rails-3.1nested-formsnested-form-for

nested_form displays a partial twice


I'm using the gem nested_form in a Rails 3.1 application. The problem is that when I click on the link generated by "link_to_add", it displays the partial twice, whereas it should display it just once. There you go some code:

Form:

<%= nested_form_for @product, :html => {:multipart => true} do |f| %>

  <%= f.fields_for :safety_info_files %>
  # adds a link for displaying the template
  <%= f.link_to_add "Add file", :safety_info_files %>
  <div class="actions">
  <%= f.submit %>
  </div>
<% end %>

Template:

<div class="fields">
  <%= f.link_to_remove "remove" %><br />
  <%= f.label :doc, "File" %>
  <%= f.file_field :doc %><br />
</div>

Did anybody else have the same problem?

EDIT:

Silly mistake, silly me. Sorry if I made some of you wasting time, the problem was that I was loading "nested_form.js" twice, so it called the function that appended the partial the same number of times.

Sorry again.


Solution

  • Silly mistake, silly me. Sorry if I made some of you wasting time, the problem was that I was loading "nested_form.js" twice, so it called the function that appended the partial the same number of times.