I suspect this just doesn''t work like I''m expecting it too,
but if I
use :allow_nil => TRUE, validation rules still complain if a form  
field is submitted empty (w/o using a presence_of rule).
So...
    validates_format_of :first_name, :with => Is_human_name,	
       :allow_nil => TRUE, :message => Is_not_human_name_msg
Will complain if the field is submitted as empty. Now, empty doesn''t  
conform to the regex I am using, but I am expecting that :allow_nil  
will cause the validation to be ignored when the value is empty.
(A) So what''s the point of allow_nil? Or am I using it incorrectly?
Ultimately what I am trying to do is have certain messages override  
the need for others.
If I have this:
    validates_presence_of :first_name
    validates_format_of :first_name, :with => Is_human_name,	
       :allow_nil => TRUE, :message => Is_not_human_name_msg
And the field is submitted as empty, then the only error message I  
need to see is the one that says the field cannot be empty. I do not  
need to see the format_of error message.
(B) What''s the typical strategy for accomplishing that?
-- gw (www.railsdev.ws)
--~--~---------~--~----~------------~-------~--~----~
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 Nov 28, 2007 3:50 PM, Greg Willits <lists-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote:> validates_format_of :first_name, :with => Is_human_name, > :allow_nil => TRUE, :message => Is_not_human_name_msgI''d drop the :allow_nil and use an :if => Proc.new { |model_name| model_name.first_name.length > 0 } -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
On Nov 28, 2007, at 2:01 PM, Greg Donald wrote:> On Nov 28, 2007 3:50 PM, Greg Willits <lists-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote: >> validates_format_of :first_name, :with => Is_human_name, >> :allow_nil => TRUE, :message => Is_not_human_name_msg > > I''d drop the :allow_nil and use an :if => Proc.new { |model_name| > model_name.first_name.length > 0 }Bulky, but it works. Thanks. -- gw (www.railsdev.ws) --~--~---------~--~----~------------~-------~--~----~ 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 Nov 28, 2007, at 1:50 PM, Greg Willits wrote:> I suspect this just doesn''t work like I''m expecting it too, but if I > use :allow_nil => TRUE, validation rules still complain if a form > field is submitted empty (w/o using a presence_of rule). > > So... > > validates_format_of :first_name, :with => Is_human_name, > :allow_nil => TRUE, :message => Is_not_human_name_msg > > Will complain if the field is submitted as empty. Now, empty doesn''t > conform to the regex I am using, but I am expecting that :allow_nil > will cause the validation to be ignored when the value is empty. > > Ultimately what I am trying to do is have certain messages override > the need for others. > > If I have this: > > validates_presence_of :first_name > > validates_format_of :first_name, :with => Is_human_name, > :allow_nil => TRUE, :message => Is_not_human_name_msg > > And the field is submitted as empty, then the only error message I > need to see is the one that says the field cannot be empty. I do not > need to see the format_of error message.Turns out :allow_blank has been added for this very purpose... http://dev.rubyonrails.org/ticket/7383 -- gw --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
true isn''t upper case ... that may have been your problem - unless you''ve defined a constant TRUE? On Nov 29, 12:18 am, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote:> On Nov 28, 2007, at 1:50 PM, Greg Willits wrote: > > > > > I suspect this just doesn''t work like I''m expecting it too, but if I > > use :allow_nil => TRUE, validation rules still complain if a form > > field is submitted empty (w/o using a presence_of rule). > > > So... > > > validates_format_of :first_name, :with => Is_human_name, > > :allow_nil => TRUE, :message => Is_not_human_name_msg > > > Will complain if the field is submitted as empty. Now, empty doesn''t > > conform to the regex I am using, but I am expecting that :allow_nil > > will cause the validation to be ignored when the value is empty. > > > Ultimately what I am trying to do is have certain messages override > > the need for others. > > > If I have this: > > > validates_presence_of :first_name > > > validates_format_of :first_name, :with => Is_human_name, > > :allow_nil => TRUE, :message => Is_not_human_name_msg > > > And the field is submitted as empty, then the only error message I > > need to see is the one that says the field cannot be empty. I do not > > need to see the format_of error message. > > Turns out :allow_blank has been added for this very purpose...http://dev.rubyonrails.org/ticket/7383 > > -- gw--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---