nested_form 显示部分两次
我在 Rails 3.1 应用程序中使用 gem Nested_form 。问题是,当我单击“link_to_add”生成的链接时,它会显示部分两次,而它应该只显示一次。你有一些代码:
表格:
<%= 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 %>
模板:
<div class="fields">
<%= f.link_to_remove "remove" %><br />
<%= f.label :doc, "File" %>
<%= f.file_field :doc %><br />
</div>
其他人有同样的问题吗?
编辑:
愚蠢的错误,愚蠢的我。抱歉,如果我让你们中的一些人浪费了时间,问题是我加载了“nested_form.js”两次,所以它调用了附加部分相同次数的函数。
再次抱歉。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
愚蠢的错误,愚蠢的我。抱歉,如果我让你们中的一些人浪费了时间,问题是我加载了“nested_form.js”两次,所以它调用了附加部分相同次数的函数。
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.
对于那些使用 Rails 4 / Turbolinks 遇到此问题并且未找到两次包含nested_form.js 的人,请尝试从 application.js 中删除 Turbolinks。一旦我这样做并退回服务器,这个问题就解决了。
来源:https://github.com/ryanb/nested_form/issues/307
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
我面临着同样的问题。
我已将nested_form.js 包含在我的应用程序布局文件中。
我没有更改我的 app/assets/javascripts/application.js 文件,它是在创建 Rails 应用程序时创建的。
当我从应用程序布局中删除条目时,问题就解决了。
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.