# nested\_attributes

**URL:** <https://discuss.rubyonrails.org/t/nested-attributes/46744>\
**Category:** rubyonrails-talk\
**Created:** [October 11, 2009, 5:27pm UTC](https://discuss.rubyonrails.org/t/nested-attributes/46744 "2009-10-11T17:27:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_McFadden](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Jeff\_McFadden](https://discuss.rubyonrails.org/u/Jeff_McFadden)\
**Post date:** [October 11, 2009, 5:27pm UTC](https://discuss.rubyonrails.org/t/nested-attributes/46744/1 "2009-10-11T17:27:34Z")

</div>

I have a user object, and a user\_profile object.

In my form I have:

\<% form\_for(:user, :url =\> object\_url, :html =\> { :method =\> :put }) do |f| %\> \<% f.fields\_for :user\_profile do |profile\_form| %\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<div\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= profile\_form.label :first\_name, t("first\_name") %\>\<br /\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= profile\_form.text\_field :first\_name %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</div\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<div\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= profile\_form.label :last\_name, t("last\_name") %\>\<br /\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= profile\_form.text\_field :last\_name %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</div\> \<% end %\>

...

In my model:

class User \< ActiveRecord::Base &nbsp;&nbsp;has\_one :user\_profile &nbsp;&nbsp;accepts\_nested\_attributes\_for :user\_profile

attr\_accessible :email, :password, :password\_confirmation, :user\_profile, :user\_profile\_attributes

And my controller is using the resource\_controller plugin.

When I go to do an update, I'm getting:

ActiveRecord::AssociationTypeMismatch (UserProfile(#2197780400) expected, got HashWithIndifferentAccess(#2159358740))

Here's my data:

Parameters: {"action"=\>"update", "\_method"=\>"put", "authenticity\_token"=\>"tkMl1SIlEf2s6wV60cAL/J7hOF2ql614cwWuI4da5lg=", "id"=\>"1", "controller"=\>"admin/users", "user"=\>{"user\_profile"=\> {"last\_name"=\>"asdf", "first\_name"=\>"asdf"}, "password\_confirmation"=\>"[FILTERED]", "role"=\>{"admin"=\>"1", "user"=\>"1"}, "password"=\>"[FILTERED]", "email"=\>"asdf@gmail.com"}}

---

<div class="post-metadata">

**Author:** ![Andrew\_France](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@Andrew\_France](https://discuss.rubyonrails.org/u/Andrew_France)\
**Post date:** [October 12, 2009, 12:55pm UTC](https://discuss.rubyonrails.org/t/nested-attributes/46744/2 "2009-10-12T12:55:12Z")

</div>

I think the parameter key for updating the user\_profile relation should be user\_profile\_attributes, I'm not sure why the fields\_for call is generating it without the suffix. Have you checked the bug tracker? I would test it without the attr\_accessible call as well.

Hope that helps, Andrew
