Rails嵌套表单link_to_add不能与表一起使用

时间:2016-11-03 12:23:09

标签: ruby-on-rails-4 nested-forms

查看 我正在使用嵌套表单link_to_add多次添加表格行。

%tbody{class: 'row_fields'}
  = f.fields_for :opening_balance, wrapper: false do |t|
    %tr
      %td= t.text_field :date, autofocus: true, class: "form-control datepicker"
      %td= t.select :break_up, options_for_select(CustomerDetail::LIST_OF_BREAK_TYPES),{}, {prompt: "select break type", class: "form-control", "data-live-search": "true"}
      %td= t.text_field :inv_no, autofocus: true, class: "form-control"
      %td= t.text_field :due_date, autofocus: true, class: "form-control datepicker"
      %td= t.text_field :amount_due, autofocus: true, class: "form-control", id: "due_amt"
      %td
        = f.link_to_add :opening_balance, id: "show_open_bal_fields", class: "nested", :data => { :target => ".row_fields"} do
          %span.glyphicon.glyphicon-plus-sign{"aria-hidden" => "true"}
    %tr
问题是当我保存表单时添加多行填充数据。它只占用表的最后一行,之前的行被禁用。在日志文件中它只显示最后一行已插入。有人请帮帮我。谢谢提前!!

1 个答案:

答案 0 :(得分:0)

确保您的代码有关系 has_many 。如果关系为has_many,您的最后一行link_to_add代码效果很好。我希望它能为您提供帮助。