Re: :allow_nil validation vs. blank?

Greg Donald
2007-11-20T20:20:16Z

On Nov 20, 2007 1:45 PM, Mike
<mike.cahill-Wuw85uim5zDR7s880joybQ@public.gmane.org>
wrote:
>
> I think I must be doing something wrong... when a form returns params
> to the controller, empty fields appear to be returned as blank, not
> nil.  so what''s the point of an :allow_nil=>true setting on a
> validation? it fails because blank is not the same as nil.

I haven''t ever found it useful either.  I use an :if => Proc.new {}
when I need optional validation.

> i would expect either returned empty fields to be nil, or :allow_nil
> to really be :allow_blank.  otherwise i have to do a search through
> params every time i do a create/update to convert blank to nil.
> totally unrailslike.  someone straighten me out please...

You might try using :default => nil in your migrations where
appropriate.  Blank values appear as NULL in the database for me when
I do that.


--
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
-~----------~----~----~----~------~----~------~--~---