# Validates\_presence\_of

**URL:** <https://www.ruby-forum.com/t/validates-presence-of/163163>\
**Category:** Rails\
**Created:** [March 17, 2009, 9:49pm UTC](https://www.ruby-forum.com/t/validates-presence-of/163163 "2009-03-17T21:49:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [March 17, 2009, 9:49pm UTC](https://www.ruby-forum.com/t/validates-presence-of/163163/1 "2009-03-17T21:49:56Z")

</div>

Hi all

I am wondering of how to use validates\_presence\_of in case I want to  
check either one of the field is present

for example  
validates\_presence\_of :phone\_number, mobile\_number

I want to check if either one presents, it accepts the request. How  
can we do that

thanks

---

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [March 17, 2009, 9:58pm UTC](https://www.ruby-forum.com/t/validates-presence-of/163163/2 "2009-03-17T21:58:44Z")

</div>

> I am wondering of how to use validates\_presence\_of in case I want to  
> check either one of the field is present
> 
> for example  
> validates\_presence\_of :phone\_number, mobile\_number
> 
> I want to check if either one presents, it accepts the request. How  
> can we do that

One way…

validates\_presence\_of :phone\_number, :if =\> Proc.new { |thing|  
thing.mobile\_number.blank? }  
validates\_presence\_of :mobile\_number, :if =\> Proc.new { |thing|  
thing.phone\_number.blank? }

Probably others as well.

---

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [March 17, 2009, 10:02pm UTC](https://www.ruby-forum.com/t/validates-presence-of/163163/3 "2009-03-17T22:02:51Z")

</div>

Another option is to have an association for different types of phones  
so that you can allow people to add as many as they need (and classify  
if it’s mobile, work, home, etc.)

On Tue, Mar 17, 2009 at 1:49 PM, Shuaib85 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> can we do that
> 
> thanks
> 
> >

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting w/Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://robbyonrails.com/](http://robbyonrails.com/)  
[http://twitter.com/planetargon](http://twitter.com/planetargon)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]
