我正在尝试在 spree 上的产品中添加一个字段,这只是一个复选框,如果它们是待售产品或者它们是内部产品,它只是用来标记产品。
我已经添加了迁移,最后想出了如何在表单上添加复选框,但是当我单击更新时,我得到了Can't mass-assign protected attributes: for_sale
这是迁移
class AddProductForSaleField < ActiveRecord::Migration
def up
add_column :spree_products, :for_sale, :boolean
end
def down
remove_column :spree_products, :for_sale
end
end
这是正在添加的字段
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
:name => "for_sale",
:insert_before => "code[erb-silent]:contains('track_inventory_levels')",
:partial => "spree/admin/products/for_sale")
这是部分
<%= f.field_container :for_sale do %>
<%= f.label :for_sale, t(:for_sale) %>
<%= f.check_box :for_sale, { :checked => true } %>
<% end %>