Hi all,

Just ran into a problem with a validates_format declaration.  In my
app, e-mail addresses need to have a proper format (of course), but
they are also optional.  Despite setting :allow_nil => true, I
consistently get an "invalid format" error whenever I submit the form
with the e-mail field blank.  This is annoying.

In the code, I see that value.nil? is being checked, but I wonder if
it should be value.blank? to properly handle the "empty string" case
of form submissions (which is probably a lot more common than a
missing value.)  I'm about to write up a spec and submit a fix for
this, but while I'm at it, I thought I'd ask what people think...

* The docs on validates_format are wrong when they say that :allow_nil
defaults to true.  It defaults to false.  I personally think maybe it
_should_ default to true: after all, if I wanted to confirm that the
field isn't empty I'd do validates_present.  Anyone disagree?  I know
that can break behavior for people who are using validates_format as
an implied validates_present, but that's a bad idea anyway, and most
other validations that use :allow_nil have it defaulting to true.
(Except validates_is_number.  Should that one change as well?)

* Should the :allow_nil option check for .blank? instead of .nil? in
all validators it's used in?  That makes the name misleading, but I
think it's more true to the expected behavior.


-- 
Have Fun,
   Steve Eley ([email protected])
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to