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.
408a4e38946d3aa2fca0450ec357d06a?d=identicon&s=25 Shuaib Zahda (shuaib85)
on 2009-03-17 22:10
(Received via mailing list)
Hi all

I want to check the presence of either one of two fields for instance,
phone number or mobile number, if either one presents, allow the
submission of the form

validates_presence_of :phone, OR :mobile

any idea how to do it
5772c599ccab3081e0fffb1d54f3b6de?d=identicon&s=25 Andrew Timberlake (andrewtimberlake)
on 2009-03-18 12:21
(Received via mailing list)
On Tue, Mar 17, 2009 at 11:09 PM, Shuaib85 <shuaib.zahda@gmail.com>
wrote:
> >
>

def validate
  errors.add(:phone, "can't be blank") if phone.blank? && mobile.blank?
  errors.add(:mobile, "can't be blank") if phone.blank? && mobile.blank?
end

or some variation of the above

Andrew Timberlake
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain
408a4e38946d3aa2fca0450ec357d06a?d=identicon&s=25 Shuaib Zahda (shuaib85)
on 2009-03-18 21:34
(Received via mailing list)
Hi

Thank you, that worked

On Mar 18, 1:20 pm, Andrew Timberlake <and...@andrewtimberlake.com>
This topic is locked and can not be replied to.