I just noticed to my surprise that Rails treats 0 and 0.0 as blank values and rejects them for validates_presence_of attributes. I knew that 0.blank? and 0.0.blank? are both true, but it never occurred to me that this is related to the validations, too. I was always, wrongly, thinking of validates_presence_of as analogous to a NOT NULL constraint. Apparently it is not. I''m undecided what to make of this. For my taste 0 and 0.0 are very present when a user enters them in a field. They are notably different from no value being entered at all. Michael -- Michael Schuerig Life is what happens mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org While you''re making plans http://www.schuerig.de/michael/ --Kevin Gilbert, A Long Day''s Life
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sep 28, 2005, at 4:52 PM, Michael Schuerig wrote:> I''m undecided what to make of this. For my taste 0 and 0.0 are very > present when a user enters them in a field. They are notably different > from no value being entered at all.I agree. For purposes of the web, foo.blank? if and only if foo.nil? or foo =~ /^\s*$/m Does anyone expect otherwise? If not, validates_presence_of should explicitly test these conditions rather than blank? Best, jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDOzxNAQHALep9HFYRAoomAJ0ZfTojCccm/vSYcU2LxYZX9oWLUQCgtc5Z Vw8bL631zo/bjnwn1rzEvzQ=edWA -----END PGP SIGNATURE-----
In article <200509290152.52791.michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org>, michael- q5aiKMLteq4b1SvskN2V4Q-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says...> I just noticed to my surprise that Rails treats 0 and 0.0 as blank > values and rejects them for validates_presence_of attributes.Could that be the same 0.13.1 bug as the validates_numericality_of rejecting 0? -- Jay Levitt | Wellesley, MA | I feel calm. I feel ready. I can only Faster: jay at jay dot fm | conclude that''s because I don''t have a http://www.jay.fm | full grasp of the situation. - Mark Adler
On Thursday 29 September 2005 03:59, Jay Levitt wrote:> In article <200509290152.52791.michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org>, michael- > q5aiKMLteq4b1SvskN2V4Q-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says... > > > I just noticed to my surprise that Rails treats 0 and 0.0 as blank > > values and rejects them for validates_presence_of attributes. > > Could that be the same 0.13.1 bug as the validates_numericality_of > rejecting 0?Yes. Is there a bug report for this? I haven''t found one. Michael -- Michael Schuerig The Fifth Rider of the Apocalypse mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org is a programmer. http://www.schuerig.de/michael/
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sep 28, 2005, at 7:46 PM, Michael Schuerig wrote:> On Thursday 29 September 2005 03:59, Jay Levitt wrote: >> In article <200509290152.52791.michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org>, michael- >> q5aiKMLteq4b1SvskN2V4Q-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says... >>> I just noticed to my surprise that Rails treats 0 and 0.0 as blank >>> values and rejects them for validates_presence_of attributes. >> >> Could that be the same 0.13.1 bug as the validates_numericality_of >> rejecting 0? > > Yes. Is there a bug report for this? I haven''t found one.I show validates_numericality_of accepting 0. Perhaps this was fixed since 0.13.1? jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDO4V+AQHALep9HFYRArWSAJ0SWwEn4T3nDHJqHCOOEFLBGPL42QCfS6hI LtOr8sCGYwUZa5lYj7W08Pk=mILw -----END PGP SIGNATURE-----
On Thursday 29 September 2005 08:11, Jeremy Kemper wrote:> On Sep 28, 2005, at 7:46 PM, Michael Schuerig wrote: > > On Thursday 29 September 2005 03:59, Jay Levitt wrote: > >> In article <200509290152.52791.michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org>, michael- > >> q5aiKMLteq4b1SvskN2V4Q-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says... > >> > >>> I just noticed to my surprise that Rails treats 0 and 0.0 as > >>> blank values and rejects them for validates_presence_of > >>> attributes. > >> > >> Could that be the same 0.13.1 bug as the validates_numericality_of > >> rejecting 0? > > > > Yes. Is there a bug report for this? I haven''t found one. > > I show validates_numericality_of accepting 0. Perhaps this was fixed > since 0.13.1?My assertion that this was the same problem was mistaken. And, yes, validates_numericality_of accepts 0 and 0.0. Michael -- Michael Schuerig You can twist perceptions mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org Reality won''t budge http://www.schuerig.de/michael/ --Rush, Show Don''t Tell