I''m trying to use validates_numericality_of on a form of mine, using :allow_nil => true, but when I submit the form with nothing filled in I still get the "is not a number" error. Help? -- seth at subimage interactive http://www.subimage.com/sublog/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
subimage interactive
2005-Dec-04 01:42 UTC
Re: validates_numericality_of, :allow_nil => true
FYI: I''m using this right now... validates_format_of :account_number, :with => /([0-9]*)/ ...but it''s just annoying me that validates_numericality_of isn''t working as advertised. On 12/3/05, subimage interactive <subimage-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m trying to use validates_numericality_of on a form of mine, using > :allow_nil => true, but when I submit the form with nothing filled in I > still get the "is not a number" error. > > Help? > > -- > seth at subimage interactive > http://www.subimage.com/sublog/ >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
subimage interactive
2005-Dec-04 02:36 UTC
Re: validates_numericality_of, :allow_nil => true
Sorry for all the spam...this works better /^[\d]*$/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
subimage interactive <subimage@...> writes:> I''m trying to use validates_numericality_of on a form of mine, using:allow_nil => true, but when I submit the form with nothing filled in I still get the "is not a number" error.Help? When you don''t fill in a field on a form, the value that gets passed to your controller is NOT nil--it''s an empty string, "" (omitting the quotes, of course). While it may seem pedantic, an empty string is still a string, not a nil. To test numericality and still allow the field to be empty you could do something like this: validates_numericality_of :some_field, :if => Proc.new {|c| not c.some_field.blank?} --Forrest