【发布时间】:2021-11-12 06:59:52
【问题描述】:
我正在使用 Cocoon Gem 构建动态表单。每件事都运行良好。我可以添加新记录,删除记录。但是我的表单和提交按钮显示了两次。我检查了application.html.erb 布局文件,但我的布局文件中没有添加 coccon。
我添加 coccon gem 的方式是在 Gemfile 中添加 gem coccon,然后使用 yarn yarn add @nathanvda/cocoon 添加 coccon 并在 application.js 文件中添加以下行
require("jquery")
require("@nathanvda/cocoon")
我的表单视图如下所示(这是显示两次的表单)
<%= form_with model: @user do |f| %>
<%= f.fields_for :work_experiences do |work_experience| %>
<div id='work_experiences'>
<%= render "work_experience_fields", f: work_experience %>
</div>
<%= link_to_add_association 'add more work experience', f, :work_experiences, data: { association_insertion_node: '#work_experiences', association_insertion_method: :append } %>
<%= f.submit 'Update Work Experience' %>
<% end %>
<% end %>
我的部分_work_experience_fields 如下所示:
<%= f.label :job_tile, 'Job Title' %>
<%= f.text_field :job_title, placeholder: 'Enter Job Title' %>
<%= f.label :company_name, 'Company Name' %>
<%= f.text_field :company_name, placeholder: 'Enter Company Name' %>
<%= link_to_remove_association "remove task", f %>
请帮我调试一下为什么我的表单显示两次。
【问题讨论】: