Ruby on rails Rails 5-保存失败后添加嵌套表单链接不工作

Ruby on rails Rails 5-保存失败后添加嵌套表单链接不工作,ruby-on-rails,Ruby On Rails,我有一张销售发票的表格,里面有一张付款记录的嵌套表格。基本上,我添加一张新发票,然后注册从客户处收到的与该发票相关的付款。当我添加新发票(在新视图中)时,这很好,但是如果保存发票失败,则添加新嵌套表单(付款记录)的链接会以一种奇怪的方式运行,因此当单击它时,它会将我带到索引页,而不是添加新的嵌套表单 The sale invoice view code . . <%= f.simple_fields_for(:sales_payment_records) do |item| %>

我有一张销售发票的表格,里面有一张付款记录的嵌套表格。基本上,我添加一张新发票,然后注册从客户处收到的与该发票相关的付款。当我添加新发票(在新视图中)时,这很好,但是如果保存发票失败,则添加新嵌套表单(付款记录)的链接会以一种奇怪的方式运行,因此当单击它时,它会将我带到索引页,而不是添加新的嵌套表单

The sale invoice view code
.
.
<%= f.simple_fields_for(:sales_payment_records) do |item| %>
  <%= render 'sales_payment_records', f: item %>
<% end %>
<%= link_to_add_pay_record_sale ' add  ', f, :sales_payment_records, 'sales_payment_records' %>
.
. countinue the sale invoice view code
当我把教程放在添加链接上时,我看到url链接是“”,但保存失败后它变成了“”。。。
任何建议

我相信您的源代码上面使用了,而您缺少了jquery部分,该部分为下一行生成了新记录

以下是采用coffee脚本格式的jquery部分:

jQuery ->
  $('form').on 'click', '.remove_fields', (event) ->
    $(this).prev('input[type=hidden]').val('1')
    $(this).closest('fieldset').hide()
    event.preventDefault()

  $('form').on 'click', '.add_fields', (event) ->
    time = new Date().getTime()
    regexp = new RegExp($(this).data('id'), 'g')
    $(this).before($(this).data('fields').replace(regexp, time))
    event.preventDefault()
您应该或可能更改部件$(此)。在。。。在表中跟随html结构标记
所以新行(tr)插入到当前表底部的新行

ohh,谢谢,但我不想使用cocoon,因为我的其他嵌套形式比问题中的复杂。谢谢,事实上,我已经有了jQuery代码,但是你的回答告诉我,在链接到JQ$('form')和JQ$('form')中,我有不同的类名称。。这是主要的错误。此外,我已将上的$('form')更改为$(document)。。。由于某些原因,我在使用“表单”时遇到了重新加载pasge的问题……现在一切都正常了:)
jQuery ->
  $('form').on 'click', '.remove_fields', (event) ->
    $(this).prev('input[type=hidden]').val('1')
    $(this).closest('fieldset').hide()
    event.preventDefault()

  $('form').on 'click', '.add_fields', (event) ->
    time = new Date().getTime()
    regexp = new RegExp($(this).data('id'), 'g')
    $(this).before($(this).data('fields').replace(regexp, time))
    event.preventDefault()