nested_form 显示部分两次

发布于 2024-12-08 05:27:06 字数 798 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

远昼 2024-12-15 05:27:06

愚蠢的错误,愚蠢的我。抱歉,如果我让你们中的一些人浪费了时间,问题是我加载了“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.

烟─花易冷 2024-12-15 05:27:06

对于那些使用 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

猥琐帝 2024-12-15 05:27:06

我面临着同样的问题。

我已将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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文