# Single Validation Error... best practices?

**URL:** <https://www.ruby-forum.com/t/single-validation-error-best-practices/180934>\
**Category:** Rails\
**Created:** [January 1, 2010, 12:04am UTC](https://www.ruby-forum.com/t/single-validation-error-best-practices/180934 "2010-01-01T00:04:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danimal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bb73d2/32.png) [@Danimal](https://www.ruby-forum.com/u/Danimal)\
**Post date:** [January 1, 2010, 12:04am UTC](https://www.ruby-forum.com/t/single-validation-error-best-practices/180934/1 "2010-01-01T00:04:56Z")

</div>

So a lot of Rails apps (mine included) have multiple validations on a  
single attribute. For example: on the password field, validating that  
it is (a) not blank, (b) matches the confirmation, (c) is at least X  
characters long, and (d) contains at least 1 alpha and at least 1  
numeric character.

The problem is: if that field is blank, the default errors shows all  
four. That’s a little intimidating to novice web users.

Is there a recommended way to somehow set the validations in an order  
of precedence and only show the first failed validation for a given  
field?

BTW, I know I can just roll my own validations or muck with the errors  
object on the model, but I’m looking to see if there is a simpler,  
recommended way to do this that I’ve overlooked.

Thoughts anyone?

-Danimal

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![Danimal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bb73d2/32.png) [@Danimal](https://www.ruby-forum.com/u/Danimal)\
**Post date:** [January 1, 2010, 12:51am UTC](https://www.ruby-forum.com/t/single-validation-error-best-practices/180934/2 "2010-01-01T00:51:45Z")

</div>

> of precedence and only show the first failed validation for a given  
> field?
> 
> BTW, I know I can just roll my own validations or muck with the errors  
> object on the model, but I’m looking to see if there is a simpler,  
> recommended way to do this that I’ve overlooked.
> 
> Thoughts anyone?

You could always set :allow\_blank =\> true on the validations (except  
the validate\_presence\_of one of course). That way they won’t appear  
unless the user has entered something.

Although, one could make an argument that if they screw up you should  
let them know what you expect so they don’t have to do it again. I  
_hate_ when a form tells me it’s too short, then it tells me it  
doesn’t have a capital letter, then it tells me it doesn’t have a  
number, then a symbol, then it complains that I can’t use 74 as it was  
the year I was born, also ‘PH’ isn’t allowed, etc. etc. etc…

And while I’m complaining, for the love of whatever it is you love,  
don’t make me enter a phone number using your pre-conceived notions  
about formatting. Just take my 10 digits and format them yourself!

Happy New Year everyone!

-philip

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
