# Nested model form error messages

**URL:** <https://www.ruby-forum.com/t/nested-model-form-error-messages/176184>\
**Category:** Rails\
**Created:** [September 25, 2009, 10:49pm UTC](https://www.ruby-forum.com/t/nested-model-form-error-messages/176184 "2009-09-25T22:49:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [September 25, 2009, 10:49pm UTC](https://www.ruby-forum.com/t/nested-model-form-error-messages/176184/1 "2009-09-25T22:49:57Z")

</div>

I have a form that updates 3 models. To the end user its just a form  
and they don’t need to know what is happening behind the scenes. My  
problem is that the error\_messages\_for prefixes errors on associations  
with their name. I have a user model that has many addresses. When  
a user is signing up errors on address fields show up as

Addresses first name can’t be blank

I would rather if it just said

=\> First name can’t be blank

Now I can get this if I do the following

=\> error\_messages\_for ‘user’, :object =\> [@user.addresses]

but then I don’t get errors on the user object like

=\> Password can’t be blank

Is there a way to tell the user object to drop errors it has on its  
associations so I can do the following

=\> error\_messages\_for ‘user’, :object =\> [@user, @user.addresses]

At the moment it will result in the first name being flagged twice.

# Addresses first name can’t be blank

# Password can’t be blank

# First name can’t be blank
