How to use Rails 4 strong parameters with has_many :through association?

后端 未结 3 1110
遇见更好的自我
遇见更好的自我 2020-12-08 00:46

I\'m having trouble getting a has_many :through association working with Rails 4\'s strong parameters. I have a model called Checkout and I need to select a per

3条回答
  •  天涯浪人
    2020-12-08 01:11

    I can post the permit statement I use in one of my controllers. This has a many to many association as well. You nest the permit array. Use the lookup association in your permit statement. The only difference should be that yours won't be nested a third time.

    In my case, the association Quote has_many :quote_items.

    QuoteItems has_many :quote_options, :through => quote_item_quote_options.

    In quotes_controller.rb

    params.require(:quote).permit(:quote_date, :good_through, :quote_number, quote_items_attributes: [:id,:quote_id, :item_name, :material_id, quote_item_quote_options_attributes:[:quote_option_id,:quote_item_id,:qty,:_destroy,:id]])
    

提交回复
热议问题