0

私は 3 つのモデルを持っています。見積もり、アイテム、および製品。

私の quote/new.html.erb は、アイテム フォームを含むパーシャルをレンダリングするように設定されており、そのアイテム フォームでは、製品を選択するためにパーシャルがレンダリングされます。

エラー: ActiveModel::MassAssignmentSecurity::QuoteController#create のエラー「保護された属性を一括割り当てできません: 製品」

(以下、関係のないものを編集しました) Quote.rb

class Quote < ActiveRecord::Base
   attr_accessible :items_attributes

   has_many :items, :dependent => :destroy
   accepts_nested_attributes_for :items
end

アイテム.rb

class Item < ActiveRecord::Base
  attr_accessible :price, :product_attributes

  belongs_to :quote
  belongs_to :product
  accepts_nested_attributes_for :product
end

製品.rb

class Product < ActiveRecord::Base
  attr_accessible :name, :item_make

  has_many :items
  accepts_nested_attributes_for :items
end

new.html.erb

<%= simple_nested_form_for @quote do |m| %>

  <%= m.simple_fields_for :items, :html => { :multipart => true } do |quoteform| %>
    <%= render "form", f: quoteform %>
  <% end %>

  <%= m.link_to_add "Add an item", :items %>
  <%= m.button :submit %>
<% end %>

_form.html.erb

<%= f.simple_fields_for :products, :html => { :multipart => true } do |x| %>
    <% render "layouts/styleselect", g: x %>
<% end %>

_styleselect.html.erb

<% g.hidden_field :item_make, :value => @item.make %>
<%= g.input :name, collection: Product.where(:item_make => 1), label: false, input_html: {:id=>"sst_style"} %>

したがって、基本的にネストされたフォームは Quote->Item->Product になりますが、item は product に属しているため、問題が発生している可能性があります。item モデルと quote モデルの両方に product_attributes または products_attributes を追加しようとしました。

どんな助けでも感謝します、ありがとう。

4

1 に答える 1