Ruby on Rails Wednesday, December 29, 2010

Hi Bente,
Thanks for your reply.

> You should use
> accepts_nested_attributes_for :department
> in your employee model.

The code you provided needed a minor tweak:

<% form.fields_for @employee.department do|department_fields| %>
was throwing an ActiveRecord::AssociationTypeMismatch -
Department(#77492292) expected, got HashWithIndifferentAccess(#37082688)

After a bit of googling I changed it to:
<% form.fields_for :department do|department_fields| %>

and everything worked fine.

Thank you once again.

P.S. In case it helps anyone else, this is described very well here:
http://guides.rubyonrails.org/2_3_release_notes.html#nested-object-forms

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment