RE: allow_nil does not

Neville Burnell
Wed, 14 Sep 2005 00:12:09 -0000

>> but part of me wishes the empty string is treated equivalent to nil.

Perhaps its better to wish for :allow_empty => true ?

On 9/13/05, Ben Bleything <ben-TGHtUsa5cOzMFIMGWPqnnw@public.gmane.org>
wrote:
> On Tue, Sep 13, 2005, Tom Davies wrote:
> > Hi,
> >
> > I am having problems getting the allow_nil to allow nil.
> >
> > I have a password field with the following validation:
> >
> >   validates_length_of :password, :minimum => 6, :allow_nil =>
true
> >
> > If I submit a form without entering the password, it comes in as
> > (printed via debug):
> >
> >   password: ''''
> >
> > The validation kicks in for the length and says it is too short.
>
> '''' is an empty string, and if I''m not mistaken,
allow_nil only allows
> the nil value.  You may need to munge your empty string to nil before
> validation.
>
> I could be wrong though :)
>
> Ben
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org