Error Messages while entering data in 2 tables with one form

validates_associated checks if the associated object (in this case
User) is a valid record.
If not, it adds an error to the UserInfo object's user method. ("User
is invalid")

"first name can't be blank" is an error on the User object's
first_name method.

If you want to display the "first name can't be blank" you'll need to
access it either through <%= error_messages_for :user %> or
@user.errors.on(:first_name)

Hope that helps

Gavin

http://handyrailstips.com

Hi Gavin,

I try following as u say
<%= error_messages_for :user %>
but it gives me same error messages.
i don't know how to use @user.errors.on(:first_name)
and where to use?

Regards,

Salil Gaikwad

To get rid of the "user is invalid", remove
validates_associated :user from the UserInfo model

Meanwhile, read up on validates_associated:
http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M002461
and make sure you want ot use it here.

Gavin

http://handyrailstips.com

To get rid of the "user is invalid", remove
validates_associated :user from the UserInfo model

Meanwhile, read up on validates_associated:
http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M002461
and make sure you want ot use it here.

Gavin

http://handyrailstips.com