我已經使用nested_form gem,只要我嘗試並向我的表單提交某些東西,即使我已將attr_accessible
放入我的模型中,我也會收到Can't mass-assign protected attributes:items
消息。Rails嵌套表單 - 無法批量分配受保護的屬性:
形式:
<%= 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的:供應商 的has_many:項目
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
你可以在哪裏調用新的,創建或update_attributes顯示相關的控制器代碼? – 2012-08-01 08:25:19
添加到我的問題! – 2012-08-01 08:27:14