# Nested\_attributes

**URL:** <https://www.ruby-forum.com/t/nested-attributes/177132>\
**Category:** Rails\
**Created:** [October 12, 2009, 10:18am UTC](https://www.ruby-forum.com/t/nested-attributes/177132 "2009-10-12T10:18:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_McFadden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@Jeff\_McFadden](https://www.ruby-forum.com/u/Jeff_McFadden)\
**Post date:** [October 12, 2009, 10:18am UTC](https://www.ruby-forum.com/t/nested-attributes/177132/1 "2009-10-12T10:18:57Z")

</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| %\>

```
  <div>
  <%= profile_form.label :first_name, t("first_name") %><br />
  <%= profile_form.text_field :first_name %>
  </div>

  <div>
  <%= profile_form.label :last_name, t("last_name") %><br />
  <%= profile_form.text_field :last_name %>
  </div>

```

\<% end %\>

…

In my model:

class User \< ActiveRecord::Base  
has\_one :user\_profile  
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”=\>“removed\_email\_address@domain.invalid”}}

---

<div class="post-metadata">

**Author:** ![Jeff\_McFadden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@Jeff\_McFadden](https://www.ruby-forum.com/u/Jeff_McFadden)\
**Post date:** [October 12, 2009, 2:56pm UTC](https://www.ruby-forum.com/t/nested-attributes/177132/2 "2009-10-12T14:56:27Z")

</div>

On Oct 12, 4:27 am, Jeff McFadden [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> <%= profile_form.text_field :first_name %>
> 
> ```
> 
> In my model:
> 
> “user”=\>“1”}, “password”=\>“[FILTERED]”, “email”=\>“removed\_email\_address@domain.invalid”}}  
> 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
