# Validates\* inside method

**URL:** <https://www.ruby-forum.com/t/validates-inside-method/190900>\
**Category:** Rails\
**Created:** [June 30, 2010, 12:18pm UTC](https://www.ruby-forum.com/t/validates-inside-method/190900 "2010-06-30T12:18:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@pepe](https://www.ruby-forum.com/u/pepe)\
**Post date:** [June 30, 2010, 12:18pm UTC](https://www.ruby-forum.com/t/validates-inside-method/190900/1 "2010-06-30T12:18:44Z")

</div>

Is there a way of using the ‘validates\*’ methods inside another  
method? For instance, I need to make sure a field is empty under a  
certain set of circumstances and contain data under a different set of  
circumstances. I would like to keep all the logic in one place and  
have the benefits of what Rails has to offer for validations,  
something like this (simplified):

validate :check\_amount

def check\_amount  
if my\_condition\_is\_true  
self.errors.add :amount, ‘should be empty.’  
else  
validates\_numericality\_of :amount # this does not work  
end  
end

Thanks in advance
