查看 我正在使用嵌套表单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
答案 0 :(得分:0)
确保您的代码有关系 has_many 。如果关系为has_many,您的最后一行link_to_add代码效果很好。我希望它能为您提供帮助。