# Help with a validation issue..? Tying 2 validations together

**URL:** <https://www.ruby-forum.com/t/help-with-a-validation-issue-tying-2-validations-together/164001>\
**Category:** Rails\
**Created:** [March 26, 2009, 7:26pm UTC](https://www.ruby-forum.com/t/help-with-a-validation-issue-tying-2-validations-together/164001 "2009-03-26T19:26:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhmspector](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@dhmspector](https://www.ruby-forum.com/u/dhmspector)\
**Post date:** [March 26, 2009, 7:26pm UTC](https://www.ruby-forum.com/t/help-with-a-validation-issue-tying-2-validations-together/164001/1 "2009-03-26T19:26:55Z")

</div>

Hi,

I am trying to validate a field upon the presence of a value of  
another field – the two are linked

for example my records have fields like this:

```
t.decimal "admin_headcount", :precision =>

```

10, :scale =\> 2, :default =\> 0.0  
t.decimal “admin\_comp”, :precision =\>  
10, :scale =\> 2, :default =\> 0.0

My forms have fields for entering of both values, however, the form  
should post an error if the user tries to submit the form if there is  
a non-zero value for headcount but the compensation amount is zero,  
and vice versa.

Is there a way to tie  
validates\_numericality\_of :admin\_comp  
validates\_numericality\_of :admin\_headcount

to each other…?  
In essence: validates\_numericality\_of :admin\_comp,  
unless :admin\_headcount \<= 0

any simple and obvious way to accomplish this…?

regards,  
DHMS

---

<div class="post-metadata">

**Author:** ![dhmspector](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@dhmspector](https://www.ruby-forum.com/u/dhmspector)\
**Post date:** [March 26, 2009, 7:52pm UTC](https://www.ruby-forum.com/t/help-with-a-validation-issue-tying-2-validations-together/164001/2 "2009-03-26T19:52:14Z")

</div>

On Thu, Mar 26, 2009 at 1:26 PM, dhmspector [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> In essence: validates\_numericality\_of :admin\_comp,  
> unless :admin\_headcount \<= 0
> 
> any simple and obvious way to accomplish this…?

validates\_numericality\_of :admin\_comp, :unless =\> Proc.new{ |r|  
r.admin\_headcount \<= 0 }

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)
