开发者

nested_form displays a partial twice

开发者 https://www.devze.com 2023-04-11 04:25 出处:网络
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 o

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开发者_如何学Python of times.

Sorry again.


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.


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


I was facing same issue.

I had included nested_form.js in my application layout file.

And I haven't changed my app/assets/javascripts/application.js file, it is as it is, when it was created at time of creating rails application.

When I removed entry from my application layout, problem was solved.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号