Re: allow_nil does not

Ben Bleything
Tue, 13 Sep 2005 15:19:11 -0000

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