Rails的茧宝石双重嵌套形式“未定义的方法”(Rails cocoon-gem double ne

2019-10-23 16:01发布

我使用的是茧宝石在我的Rails应用程序,并尝试双窝形式。

第一个“link_to_add_association补充说:”它包含另一个“link_to_add_association”的valve_fields部分它给这个错误:

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 

Answer 1:

根据您的rfq_params方法,您有line_items_attributesvalve_attributes 。 这意味着line_itemsnested的内部valve ,所以在你的表格,你应该改变这一行f.simple_fields_for :line_items do |line_item|valve.simple_fields_for :line_items do |line_item|



文章来源: Rails cocoon-gem double nested forms “undefined method”