添加accepts_nested_attributes_for时,Fields_for消失
我在Rails 3.2.5中做了一个嵌套的表单,但是当我添加accepts_nested_attributes_for
我的fields_for
消失时(它们只是停止在我的表单中显示)。
这是我的模特:
class Product < ActiveRecord::Base attr_accessible :title, :description, :variants_attributes has_many :variants accepts_nested_attributes_for :variants validates :title, presence: true end
我的第二个模特是
class Variant < ActiveRecord::Base belongs_to :product attr_accessible :price, :sku, :weight, :inventory_quantity, :product_id end
在我看来,我有
{:multipart => true} do |f| %>
_inventory_fields.html.erb
**之间的部分是未打印的部分。 当我在我的产品模型fields_中删除accepts_nested_attributes_for时,再次开始显示,但我的表单不起作用。
发生了什么?!?!
在控制器新动作调用中
@product.varients.build
这应该在产品varient集合中创建1 in memory varient,它应该绑定到的字段