我在我的rails应用程序中使用cocoon gem并尝试双重嵌套表单。
第一个" link_to_add_association"添加了valve_fields partial,其中包含另一个" link_to_add_association"它给出了这个错误:
ActionView::Template::Error (undefined method `fetch_value' for nil:NilClass):
21: .line_items
22: =f.simple_fields_for :line_items do |line_item|
23: =render 'line_item_fields', :f => line_item
24: //error line// =link_to_add_association "add line", f, :line_items
我没有为第一个链接做任何不同的事情而不是第二个链接,但由于某种原因它不会工作
//Rfq controller
def rfq_params
params.require(:rfq).permit(
:quote_number,:rep_id, :owner, :customer_id, :customer_name, :end_user_list, :application_list, :due, :ship_date, :is_budgetary, :notes, :mandatory_due_date,
valves_attributes: [:id, :_destroy, :productline, :discwedge, :valvetype, :valveends, :valvematerial, :valveconfig, :valvenotes,
line_items_attributes: [
:tag, :qty, :size, :class, :operator, :trim, :_destroy
]
])
end
//form partial:
.valves
=f.fields_for :valves do |valve|
=render 'valve_fields', :f => valve
=link_to_add_association 'add valve', f, :valves, "data-association-insertion-traversal" => "next"
//valve partial
.line_items
=f.simple_fields_for :line_items do |line_item|
=render 'line_item_fields', :f => line_item
=link_to_add_association "add line", f, :line_items
答案 0 :(得分:1)
根据您的rfq_params
方法,您line_items_attributes
内valve_attributes
。这意味着line_items
nested
位于valve
内,因此在您的表单中,您应该将此行f.simple_fields_for :line_items do |line_item|
更改为valve.simple_fields_for :line_items do |line_item|
。