Forum: Ruby on Rails validates_presence_of

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Shuaib Z. (Guest)
on 2009-03-17 22:49
(Received via mailing list)
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
Philip H. (Guest)
on 2009-03-17 22:58
(Received via mailing list)
> 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.
Robby R. (Guest)
on 2009-03-17 23:02
(Received via mailing list)
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>
wrote:
> can we do that
>
> thanks
>
> >
>



--
Robby R.
Chief Evangelist, Partner

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

http://planetargon.com/
http://robbyonrails.com/
http://twitter.com/planetargon
aim: planetargon

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4068 [fax]
This topic is locked and can not be replied to.