Interesting Things
Integer("008") != "008".to_i
The
to_imethod is what you want, unless you want exceptions or octal numbers.Somebody needed help constructing a
named_scopewhere they could reference the count of an associatedhas_manyassociation. There was some grumbling about using:joinsand:group(and if you do this, be sure not to callcounton the scope itself without also doing a:select => 'DISTINCT primary_key'). The winning solution was to just put a counter_cache on the association and use the denormalized column instead.








Javascript's parseInt() has a similar issue:
parseInt("8") === 8parseInt("08") === 0
parseInt("010") === 8
One solution is to include the radix:
parseInt("08", 10) === 8Or use the Number function or constructor:
Number("08") === 8new Number("08") === 8
Another trick is to convert the string using the + operator:
+"08" === 8remove