1

製品の作成時にこのフォームを使用してみてください:

これはproduct_formにあります:

<%= f.fields_for :feature do |ft| %>
    <%= ft.label :name %>
    <%= ft.text_field :name %>  
    <%= ft.label :value %>
    <%= ft.text_field :value %>
<% end %>

しかし、作成しようとすると、このエラーが発生します

Can't mass-assign protected attributes: feature

これを私の製品モデルに入れてみてください:

 attr_accessible :code, :description, :price, :title,:image_1,:image_2,:image_3,:image_4,:image_5,:image_6,:image_7,:image_8,:features_attributes # and feature_attributes meet


  accepts_nested_attributes_for :features

しかし、同じエラーが発生します。私の関連付けは

product.rb

  has_many :features

機能.rb

  belongs_to :product

ネストされた属性クラスが表示されますが、エラーが続くため見つかりません:

http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

エラーは次のとおりです。

Can't mass-assign protected attributes: feature

誰かが私を助けることができれば、とても感謝しています。

4

1 に答える 1