allow_nil does not

Tom Davies
Tue, 13 Sep 2005 16:44:14 -0000

I have a feeling you are right....

I guess the alternative is that it might overwrite the password to
nothing... but part of me wishes the empty string is treated
equivalent to nil.

Oh well... I will just grab it and nillify it before validation.

Thanks,
Tom

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
>