# Nested object problems

**URL:** <https://discuss.rubyonrails.org/t/nested-object-problems/58973>\
**Category:** rubyonrails-talk\
**Created:** [May 15, 2011, 2:35am UTC](https://discuss.rubyonrails.org/t/nested-object-problems/58973 "2011-05-15T02:35:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [May 15, 2011, 2:35am UTC](https://discuss.rubyonrails.org/t/nested-object-problems/58973/1 "2011-05-15T02:35:52Z")

</div>

Im making nested attributes for profile on the user model and I also need to validate the profile info so I put

User model

&nbsp;&nbsp;has\_one :profile &nbsp;&nbsp;accepts\_nested\_attributes\_for :profile &nbsp;&nbsp;validates\_associated :profile \<--- To validate values &nbsp;&nbsp;attr\_accessible :profile \<----to allow mass assingment

Profile model

&nbsp;&nbsp;belongs\_to :user, :dependent =\> :destroy &nbsp;&nbsp;\>\>\> Some Validations \<\<\<

But Im getting

Profile(#30752520) expected, got ActiveSupport::HashWithIndifferentAccess(#26724528)

Becouse of the &nbsp;&nbsp;attr\_accessible :profile I think, but if I dont have that line I cant enter values for profile, Anyways. when I take that line off, my profile forms isn't validated, this problem come when changing to rails 3.0.7

---

<div class="post-metadata">

**Author:** ![M\_Daubs](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@M\_Daubs](https://discuss.rubyonrails.org/u/M_Daubs)\
**Post date:** [May 15, 2011, 12:07pm UTC](https://discuss.rubyonrails.org/t/nested-object-problems/58973/2 "2011-05-15T12:07:50Z")

</div>

Hi Tomas,

Try changing your mass-assignment protection line to:

&nbsp;&nbsp;&nbsp;&nbsp;attr\_accessible :profile\_attributes

If that still doesn't work send your view code. If you haven't already ready read the nested attribute docs, they explain things pretty well: [ActiveRecord::NestedAttributes::ClassMethods](http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html)

Matt Daubert

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [May 15, 2011, 3:06pm UTC](https://discuss.rubyonrails.org/t/nested-object-problems/58973/3 "2011-05-15T15:06:48Z")

</div>

I added that line but still dont work

User Form

\<%= form\_for @user do |f| %\> \<%= render 'shared/error\_messages', :record =\> @user %\>

> > > Some Field Tags \<\<\<

&nbsp;&nbsp;\<p\> &nbsp;&nbsp;\<%= f.fields\_for @user.build\_profile do |builder| %\> &nbsp;&nbsp;\<%= render 'profile\_form', :f =\> builder %\> &nbsp;&nbsp;\<% end %\> &nbsp;&nbsp;\</p\> &nbsp;&nbsp;\<p\>\<%= f.submit (@user.new\_record? ? "Registrarse" : "Editar") %\>\</p\> \<% end %\>

Profile Fields

\<p\> \<%= f.label :name %\>\<br /\> \<%= f.text\_field :name %\> \</p\> \<p\> \<%= f.label :surname %\>\<br /\> \<%= f.text\_field :surname %\> \</p\>

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [May 15, 2011, 5:41pm UTC](https://discuss.rubyonrails.org/t/nested-object-problems/58973/4 "2011-05-15T17:41:50Z")

</div>

Fixed: Changed @user.build\_profile from view to controller
