# Best way to nest model validations

**URL:** <https://www.ruby-forum.com/t/best-way-to-nest-model-validations/139040>\
**Category:** Rails\
**Created:** [May 30, 2008, 11:23am UTC](https://www.ruby-forum.com/t/best-way-to-nest-model-validations/139040 "2008-05-30T11:23:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kieran\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a4c791/32.png) [@Kieran\_P](https://www.ruby-forum.com/u/Kieran_P)\
**Post date:** [May 30, 2008, 11:23am UTC](https://www.ruby-forum.com/t/best-way-to-nest-model-validations/139040/1 "2008-05-30T11:23:08Z")

</div>

Hey everyone,

Whats the best way to nest model validations so multple errors relating  
to  
the same field appear one by one, rather than all at once? I was talking  
with some people on IRC the other day, but two of the ideas I got appear  
to  
be things that would be nice to have in RoR, but arn’t right now (the  
ability to add blocks or if statments, like follows)

validates\_presence\_of :email do  
validates\_format\_of :email, :with =\>  
/^[A-Za-z0-9.\_%±]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/  
end

OR

if validates\_presence\_of :email  
validates\_format\_of :email, :with =\>  
/^[A-Za-z0-9.\_%±]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/  
end

Neither of these work however, and rather than going into lots of :if =\>  
and  
functions checking if other variables are set and such, I was wondering  
if  
anyone knew or a gem, plugin, or RoR function to assit with this. Your  
help  
is much appreciated.

–  
Regards  
Kieran

---

<div class="post-metadata">

**Author:** ![Kieran\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a4c791/32.png) [@Kieran\_P](https://www.ruby-forum.com/u/Kieran_P)\
**Post date:** [May 30, 2008, 11:38am UTC](https://www.ruby-forum.com/t/best-way-to-nest-model-validations/139040/2 "2008-05-30T11:38:22Z")

</div>

You could overwrite the validate method and manually add errors. Then  
you can use simple if then constructs to check the fields.
