我尝试在创建产品时使用此表单:
这是在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
但得到同样的错误,我的联想是
产品.rb
has_many :features
特征.rb
belongs_to :product
我看到了嵌套的属性类,但没有找到,因为错误仍然存在:
http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
错误是:
Can't mass-assign protected attributes: feature
如果有人可以帮助我非常非常非常感谢。