# Validates\_presence\_of validation order?

**URL:** <https://www.ruby-forum.com/t/validates-presence-of-validation-order/87179>\
**Category:** Rails\
**Created:** [March 25, 2006, 11:04pm UTC](https://www.ruby-forum.com/t/validates-presence-of-validation-order/87179 "2006-03-25T23:04:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhagemeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@jhagemeier](https://www.ruby-forum.com/u/jhagemeier)\
**Post date:** [March 25, 2006, 11:04pm UTC](https://www.ruby-forum.com/t/validates-presence-of-validation-order/87179/1 "2006-03-25T23:04:57Z")

</div>

I have a form with 3 fields: user\_id, email and password.  
All 3 fields are required, so I have a “validates\_presence\_of :user\_id,  
:email, :password” in my model.  
Works, but the validation errors show up in a different order than I  
specificed in the validates\_presence\_of statement.

Is there a way to specify the order in which the validations (and  
corresponding error messages) should occur using the built in validation  
methods like validates\_presence\_of?

Thanks for the assistance,  
Jeff

---

<div class="post-metadata">

**Author:** ![jhagemeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@jhagemeier](https://www.ruby-forum.com/u/jhagemeier)\
**Post date:** [March 25, 2006, 11:42pm UTC](https://www.ruby-forum.com/t/validates-presence-of-validation-order/87179/2 "2006-03-25T23:42:22Z")

</div>

> Is there a way to specify the order in which the validations (and  
> corresponding error messages) should occur using the built in validation  
> methods like validates\_presence\_of?

Have you tried:

validates\_presence\_of :user\_id

validates\_presence\_of :email

validates\_presence\_of :password

Lindsay

---

<div class="post-metadata">

**Author:** ![jhagemeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@jhagemeier](https://www.ruby-forum.com/u/jhagemeier)\
**Post date:** [March 25, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/validates-presence-of-validation-order/87179/3 "2006-03-25T23:55:18Z")

</div>

Lindsay B. wrote:

> Have you tried:
> 
> validates\_presence\_of :user\_id
> 
> validates\_presence\_of :email
> 
> validates\_presence\_of :password
> 
> Lindsay

Yes, same results: email can’t be blank, followed by user id then  
password

Jeff

---

<div class="post-metadata">

**Author:** ![jhagemeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@jhagemeier](https://www.ruby-forum.com/u/jhagemeier)\
**Post date:** [March 26, 2006, 4:29am UTC](https://www.ruby-forum.com/t/validates-presence-of-validation-order/87179/4 "2006-03-26T04:29:57Z")

</div>

I think the validation targets are stored in a hash, in which order is  
never guaranteed.

Seems like someone was annoyed with this a while back and created a  
plugin to control  
order of validation… EZ was that you? Hmm, actually I think it was  
another  
over-achiever… Well, you might search the wiki and/or google for it.

b
