Felder für verschwinden, wenn accept_nested_attributes_for hinzugefügt wird
Ich mache ein verschachteltes Formular in Rails 3.2.5, aber wenn ich das hinzufügeaccepts_nested_attributes_for
meinefields_for
verschwinden (sie werden in meinem Formular nicht mehr angezeigt).
Das sind meine Modelle:
class Product < ActiveRecord::Base
attr_accessible :title, :description, :variants_attributes
has_many :variants
accepts_nested_attributes_for :variants
validates :title, presence: true
end
Mein zweites Modell ist
class Variant < ActiveRecord::Base
belongs_to :product
attr_accessible :price, :sku, :weight, :inventory_quantity, :product_id
end
Und aus meiner Sicht habe ich
<%= 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 do |variant| %>
<%= render 'inventory_fields', f: variant %>
<% end %>**
<div class="actions">
<%= f.submit 'Guardar', class: 'btn btn-primary' %>
</div>
<% end %>
_inventory_fields.html.erb
<div class="control-group">
<%= f.label :inventory_quantity, 'How many are in stock?', class: 'control-label' %>
<div class="controls">
<%= f.text_field :inventory_quantity, class: 'span1', value: '1' %>
</div>
</div>
Der Teil zwischen dem ** ist derjenige, der nicht gedruckt wird. Und wenn ich accept_nested_attributes_for in meinem Produktmodell entferne, werden fields_for wieder angezeigt, aber mein Formular funktioniert nicht.
Was ist los?!?!