# Want to get one-by-one error message

**URL:** <https://www.ruby-forum.com/t/want-to-get-one-by-one-error-message/186412>\
**Category:** Rails\
**Created:** [April 6, 2010, 7:01pm UTC](https://www.ruby-forum.com/t/want-to-get-one-by-one-error-message/186412 "2010-04-06T19:01:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rutisyrz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@rutisyrz](https://www.ruby-forum.com/u/rutisyrz)\
**Post date:** [April 6, 2010, 7:01pm UTC](https://www.ruby-forum.com/t/want-to-get-one-by-one-error-message/186412/1 "2010-04-06T19:01:59Z")

</div>

Dear all,

In RoR, on one form if I 've applied validations to 7 fields & while  
running an application if user insert invalid values in i.e. 3 fields at  
that time RoR shows error message for all 3 fields.

I want error messages to be shown one-by-one…

Like if user correct first field then only he 'll get error for second  
field not before that.

Thanking you…

---

<div class="post-metadata">

**Author:** ![rutisyrz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@rutisyrz](https://www.ruby-forum.com/u/rutisyrz)\
**Post date:** [April 7, 2010, 10:14am UTC](https://www.ruby-forum.com/t/want-to-get-one-by-one-error-message/186412/2 "2010-04-07T10:14:06Z")

</div>

> In RoR, on one form if I 've applied validations to 7 fields & while  
> running an application if user insert invalid values in i.e. 3 fields at  
> that time RoR shows error message for all 3 fields.
> 
> I want error messages to be shown one-by-one…
> 
> Like if user correct first field then only he 'll get error for second  
> field not before that.

That sounds worse for the user, they have to submit each time only to be  
told “hang on, there’s something else wrong - I knew about it before but  
you’re too stupid to be told more than one thing at a time”.

However, it’s your app…

I’d recommend using the @object.errors enumerator yourself rather than  
just  
relying on error\_messages\_for. For example:

error = @object.errors.first  
if error  
attr,msg = error  
if attr != “base”  
content\_tag :div, “#{attr} #{msg}”, :class =\> “my\_error”  
else  
content\_tag :div, “#{msg}”, :class =\> “my\_error”  
end  
end

You’d probably want to put this in a helper, but that’s the basics of  
what  
you want to do…

Hope that helps.

Cheers,

Andy

---

<div class="post-metadata">

**Author:** ![rutisyrz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@rutisyrz](https://www.ruby-forum.com/u/rutisyrz)\
**Post date:** [April 7, 2010, 7:46pm UTC](https://www.ruby-forum.com/t/want-to-get-one-by-one-error-message/186412/3 "2010-04-07T19:46:43Z")

</div>

> That sounds worse for the user, they have to submit each time only to be  
> told “hang on, there’s something else wrong - I knew about it before but  
> you’re too stupid to be told more than one thing at a time”.
> 
> * * *

dear Andy,

Thanks for your help… I too know it’s stupidity to show one-by-one  
message

but while you work as developer you need to follow requirements given by  
client & that 's strictly professional in big industry…

Regards  
Rutvij

---

<div class="post-metadata">

**Author:** ![rutisyrz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@rutisyrz](https://www.ruby-forum.com/u/rutisyrz)\
**Post date:** [April 7, 2010, 9:13pm UTC](https://www.ruby-forum.com/t/want-to-get-one-by-one-error-message/186412/4 "2010-04-07T21:13:20Z")

</div>

> dear Andy,
> 
> Thanks for your help… I too know it’s stupidity to show one-by-one  
> message
> 
> but while you work as developer you need to follow requirements given by  
> client & that 's strictly professional in big industry…

I agree, I’ve had to do some daft things for a client (that I’m still  
working with) that have nearly caused me to be laughed out of IRC  
channels…

Hopefully the message also gave you ideas for a solution.

Cheers,

Andy
