这是我的嵌套表单的相关部分:
<div class="field">
<%= f.fields_for "@partcode" do |p|%>
<%= p.label "partcode"%><br />
<%= p.text_field :partcode %>
<% end %>
</div>
我的模型中已经有了这个:
attr_accessible :partcode,
:description
但是,当我在表单中输入内容时,出现此错误:
Can't mass-assign protected attributes: @partcode
这是我的零件代码模型:
class Partcode < ActiveRecord::Base
attr_accessible :partcode,
:description
validates :partcode,
:description,
:presence => true
belongs_to "goods_ins"
accepts_nested_attributes_for "goods_ins"
end
这是我的商品模型中的所有代码:
class GoodsIn < ActiveRecord::Base
attr_accessible :c4lpono,
:courier,
:deliverydate,
:deliverynoteno,
:description,
:destination,
:notes,
:partcode,
:quantity,
:signedby,
:suppliername
validates :deliverydate,
:deliverynoteno,
:destination,
:quantity,
:signedby,
:suppliername,
:presence => true
has_many :suppliers
has_many :partcodes
accepts_nested_attributes_for :partcodes
end
这也是new
我的零件代码控制器的一部分:
def new
@partcode = Partcode.new
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @partcode }
end
end