# How to display validation error messages for multiple record

**URL:** <https://www.ruby-forum.com/t/how-to-display-validation-error-messages-for-multiple-record/51606>\
**Category:** Rails\
**Created:** [January 4, 2006, 6:07am UTC](https://www.ruby-forum.com/t/how-to-display-validation-error-messages-for-multiple-record/51606 "2006-01-04T06:07:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex\_nesbitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecd19e/32.png) [@alex\_nesbitt](https://www.ruby-forum.com/u/alex_nesbitt)\
**Post date:** [January 4, 2006, 6:07am UTC](https://www.ruby-forum.com/t/how-to-display-validation-error-messages-for-multiple-record/51606/1 "2006-01-04T06:07:55Z")

</div>

I am trying to figure out how to display model validation error messages  
for  
a multiple record form.

My form is for setting up new accounts and collects information for two  
models - Accounts and Users.

My create method collects the parameters from the form and adds them to  
a  
Account object and a User object then runs account.valid? and  
user.valid?.  
If it’s valid it updates the models ok, if not valid I get error  
messages  
for accounts to display on my form page but not user validation error  
messages. I have validations set in both models.

I would like to collect all the validation error messages from both  
models  
and put them in one error display box at the top of the form and then  
highlight any input boxes that need to be fixed.

Any ideas how to do this?

thanks  
Alex

---

<div class="post-metadata">

**Author:** ![alex\_nesbitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecd19e/32.png) [@alex\_nesbitt](https://www.ruby-forum.com/u/alex_nesbitt)\
**Post date:** [January 24, 2006, 5:56am UTC](https://www.ruby-forum.com/t/how-to-display-validation-error-messages-for-multiple-record/51606/2 "2006-01-24T05:56:45Z")

</div>

Alex, I am facing a similar issue. Did u find a solution to this  
problem?

-Jeet

alex nesbitt wrote:

> I am trying to figure out how to display model validation error messages  
> for  
> a multiple record form.
> 
> My form is for setting up new accounts and collects information for two  
> models - Accounts and Users.
> 
> My create method collects the parameters from the form and adds them to  
> a  
> Account object and a User object then runs account.valid? and  
> user.valid?.  
> If it’s valid it updates the models ok, if not valid I get error  
> messages  
> for accounts to display on my form page but not user validation error  
> messages. I have validations set in both models.
> 
> I would like to collect all the validation error messages from both  
> models  
> and put them in one error display box at the top of the form and then  
> highlight any input boxes that need to be fixed.
> 
> Any ideas how to do this?
> 
> thanks  
> Alex

---

<div class="post-metadata">

**Author:** ![alex\_nesbitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecd19e/32.png) [@alex\_nesbitt](https://www.ruby-forum.com/u/alex_nesbitt)\
**Post date:** [January 24, 2006, 6:48am UTC](https://www.ruby-forum.com/t/how-to-display-validation-error-messages-for-multiple-record/51606/3 "2006-01-24T06:48:38Z")

</div>

One solution is to grab the errors and loop them yourself.

errors = Class1.errors.full\_messages + Class2.errors.full\_messages

Better yet, write a plugin for error\_messages\_for that will take a  
single  
object name or hash of object names to display errors for?

I have an error\_messages\_for plugin coming soon that I may incorporate  
this  
into. I’ll look at that later tonight.

Cheers,

Bob S.
