[Rails-core] Re: coercions of blank strings to boolean and integer values

2008-08-21 Thread Chris Cruft
Damian, I think we are saying the same thing: using the object's own methods (to_i, to_a, to_f, etc.) to typecast/coerce is absolutely the right thing to do. Unfortunately, Rails currently goes beyond that level of coercion and Josh's original proposal on this post was to go even further to

[Rails-core] Re: coercions of blank strings to boolean and integer values

2008-08-21 Thread Michael Koziarski
I think we are saying the same thing: using the object's own methods (to_i, to_a, to_f, etc.) to typecast/coerce is absolutely the right thing to do. Unfortunately, Rails currently goes beyond that level of coercion and Josh's original proposal on this post was to go even further to coerce

[Rails-core] Re: coercions of blank strings to boolean and integer values

2008-08-20 Thread Chris Cruft
+1 for when :integer then value.to_i And if I get up on the wrong side of the bed, then I might propose when :integer then value Honestly, having the persistence layer guess at what is intended to be stored seems like a losing proposition. What's next? Guessing that for a boolean field Nein

[Rails-core] Re: coercions of blank strings to boolean and integer values

2008-08-19 Thread Chris Cruft
The scenario that you mention is a classic one of empty strings being returned from forms. And the problem is bigger than just booleans. It also applies to strings, numbers and lists. In the scenario Josh mentions, a boolean field should have the empty string or a blank string coerced to false

[Rails-core] Re: coercions of blank strings to boolean and integer values

2008-08-19 Thread Chad Woolley
On Tue, Aug 19, 2008 at 4:58 AM, Chris Cruft [EMAIL PROTECTED] wrote: Putting the burden on ActiveRecord to massage the crap it is handed into something meaningful seems out of place. Why not fix the problem at the source and get ActionController to return meaningful values from empty form

[Rails-core] Re: coercions of blank strings to boolean and integer values

2008-08-19 Thread Ryan Bates
On Aug 19, 8:38 am, Ian White [EMAIL PROTECTED] wrote: I also agree - ActiveRecord should not need to know about how browsers   handle params hashes.  For example, If you're talking to ActiveRecord   from somewhere else (the console, a drb script, or whatever) you   shouldn't have to