我使用了nested_form gem,每当我尝试向我的表单提交一些东西时,我都会收到Can't mass-assign protected attributes:items
消息,即使我已经放入attr_accessible
了我的模型。
形式:
<%= nested_form_for(@goods_in) do |f| %>
...
<%= f.fields_for :items do |i| %>
<td><%= i.text_field :description, :autocomplete => :off%></td>
<td><%= i.text_field :quantity, :autocomplete => :off %></td>
<th><%= i.link_to_remove "Remove this item" %></th>
<% end %>
<%= f.submit :"Submit Delivery" %>
<% end %>
模型中的商品:类 GoodsIn < ActiveRecord::Base belongs_to :supplier has_many :items
attr_accessible :c4lpono,
:courier,
:deliverydate,
:deliverynoteno,
:destination,
:notes,
:quantity,
:signedby,
:supplier_id,
:partcode_ids
accepts_nested_attributes_for :supplier
validates :c4lpono,
:deliverydate,
:deliverynoteno,
:destination,
:quantity,
:signedby,
:presence =>true
end
项目型号
class Item < ActiveRecord::Base
belongs_to :goods_in
attr_accessible :quantity,
:partcode,
:description,
:goods_in_id
accepts_nested_attributes_for :goods_in
end
控制器中的货物:
def create
@goods_in = GoodsIn.new(params[:goods_in])
end