Nested object problems

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

User model

  has_one :profile   accepts_nested_attributes_for :profile   validates_associated :profile <--- To validate values   attr_accessible :profile <----to allow mass assingment

Profile model

  belongs_to :user, :dependent => :destroy   >>> Some Validations <<<

But Im getting

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

Becouse of the   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

Hi Tomas,

Try changing your mass-assignment protection line to:

    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

Matt Daubert

I added that line but still dont work

User Form

<%= form_for @user do |f| %> <%= render 'shared/error_messages', :record => @user %>

Some Field Tags <<<

  <p>   <%= f.fields_for @user.build_profile do |builder| %>   <%= render 'profile_form', :f => builder %>   <% end %>   </p>   <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>

Fixed: Changed @user.build_profile from view to controller