Somehow, I was under impression that accepts_nested_attributes_for
will let me populate child object through parent:
person.update_attributes person_hash
but in practice I ended up doing this:
person.address.update_attributes person_hash[:address]
person_hash.delete :address
person.update_attributes person_hash
Now, http://guides.rubyonrails.org mentions accepts_nested_attributes_for only indirectly and API documentation for this method is also quite cryptic.
1) Could someone show basic use-case for accepts_nested_attributes_for? I mean, I understand how it's declared, I'm confused about the difference it makes.
2) Is the way I populate nested object the 'right' one in rails, or there's something more 'elegant'?
Thanks!
update
Model, for clarity
class Person < ActiveRecord::Base
has_one :address
accepts_nested_attributes_for :address
end
update2, for j.
Form declaration goes like this
<% fields_for "people", person, :index => person.id do |person_form| %>
...
<% person_form.fields_for person.address do |address_form| %>
<%= address_form.text_field :street %>
<% end %>
...
<% end %>
But it gives me html names like people[66][address][street]
and not people[66][address_attributes][street]