When using validates_format_of I am not able to enter a nil value? It''s a mute point that I think that validates_format_of should NOT do the job of validates_presence_of, but how should i get around this? I want to validate a field only if someone has entered something in, otherwise i do not want it to validate nothing. I do not mind if he user enters nothing, but if they intend for something to be there, it needs the correct format. HELP!? thanks! mk -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Validations provide mechanisms to do what you''re asking. See the API on validations for more info. Possible solutions can be found via google "validates_format_of nil" http://significantbits.wordpress.com/2007/03/02/apply-rails-validation-rules-only-when-the-attribute-is-not-nil/ http://brighter.net/2007/6/23/validates_format_of-something-without-validates_presence_of Good luck! On 9/25/07, Mason Kessinger <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > When using validates_format_of I am not able to enter a nil value? > > It''s a mute point that I think that validates_format_of should NOT do > the job of validates_presence_of, but how should i get around this? > > I want to validate a field only if someone has entered something in, > otherwise i do not want it to validate nothing. I do not mind if he user > enters nothing, but if they intend for something to be there, it needs > the correct format. > > HELP!? > > thanks! > mk > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
validates_format_of :foo, :with => /bar/, :if => Proc.new(|o| o.foo != nil } Mason Kessinger wrote:> When using validates_format_of I am not able to enter a nil value? > > It''s a mute point that I think that validates_format_of should NOT do > the job of validates_presence_of, but how should i get around this? > > I want to validate a field only if someone has entered something in, > otherwise i do not want it to validate nothing. I do not mind if he user > enters nothing, but if they intend for something to be there, it needs > the correct format. > > HELP!? > > thanks! > mk >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you! :allow_nil => true did not work (though some said it worked fine for them) :if => column_name? did work though. Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
:allow_nil works for most of the validates_ calls, but it is not an option of validates_format_of Mason Kessinger wrote:> Thank you! > > :allow_nil => true > > did not work (though some said it worked fine for them) > > :if => column_name? > > did work though. > > Thanks! >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---