11155
(-- --)
May 15, 2011, 2:35am
#1
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
M_Daubs
(M Daubs)
May 15, 2011, 12:07pm
#2
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: http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
Matt Daubert
11155
(-- --)
May 15, 2011, 3:06pm
#3
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>
11155
(-- --)
May 15, 2011, 5:41pm
#4
Fixed: Changed @user.build_profile from view to controller