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