我在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
Run Code Online (Sandbox Code Playgroud)
我的第二个模特是
class Variant < ActiveRecord::Base
belongs_to :product
attr_accessible :price, :sku, :weight, :inventory_quantity, :product_id
end
Run Code Online (Sandbox Code Playgroud)
在我看来,我有
<%= form_for [:admin, @product], :html => {:multipart => true} do |f| %>
<%= render 'admin/shared/error_messages', object: f.object %>
<fieldset>
<legend>Producto Nuevo</legend>
<div class="control-group">
<%= f.label :title, 'Título', class: 'control-label' %>
<div class="controls">
<%= f.text_field :title %>
</div>
</div>
**<%= f.fields_for :variants …Run Code Online (Sandbox Code Playgroud) ruby-on-rails nested-attributes fields-for ruby-on-rails-3 ruby-on-rails-3.2