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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 thatOne 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 <shuaib.zahda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > > >-- Robby Russell 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] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Mar 17, 2009 at 11:09 PM, Shuaib85 <shuaib.zahda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > >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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Thank you, that worked On Mar 18, 1:20 pm, Andrew Timberlake <and...-642hCh26+Dt3UeSHeRwt+FaTQe2KTcn/@public.gmane.org> wrote:> On Tue, Mar 17, 2009 at 11:09 PM, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 > > 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 Timberlakehttp://ramblingsonrails.comhttp://www.linkedin.com/in/andrewtimberlake > > "I have never let my schooling interfere with my education" - Mark Twain--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---