Fields_for znikają po dodaniu accepts_nested_attributes_for
Robię zagnieżdżoną formę w Railsach 3.2.5, ale kiedy dodamaccepts_nested_attributes_for
mójfields_for
znikają (po prostu przestają pokazywać się w mojej formie).
To są moje modele:
class Product < ActiveRecord::Base
attr_accessible :title, :description, :variants_attributes
has_many :variants
accepts_nested_attributes_for :variants
validates :title, presence: true
end
Mój drugi model to
class Variant < ActiveRecord::Base
belongs_to :product
attr_accessible :price, :sku, :weight, :inventory_quantity, :product_id
end
I moim zdaniem mam
<%= 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>
Część między ** to ta, która nie jest drukowana. A kiedy usuwam accepts_nested_attributes_for w moim modelu produktu, pola_w celu ponownego wyświetlenia, ale mój formularz nie będzie działać.
Co się dzieje?!?!