Ruby on Rails Mangles Decimal Type to Integer

So when is a DECIMAL not a DECIMAL? Go ahead, take your time. I'll wait.

A decimal type is converted to an integer by Ruby on Rails through its infinite wisdom. As seen in active\_record\connection\_adapters\abstract\schema\_definitions.rb, line 180 (in Rails 1.2.3):

when /decimal|numeric|number/i
extract_scale(field_type) == 0 ? :integer : :decimal

So, apparently, Rails thinks, "Well, I know you specified a decimal type, but hey, you didn't specify a scale, so you must have made a typo! Here, let me just change that to integer for you."

Or, in other words:

You: I'd like a hamburger with nothing on it.

Rails: OK, here's your hot dog.

You: WTF??!?

Apparently, this issue has been reported before. However, as of Version 1.2.3 of Rails, this issue still exists.

I've just opened a new issue on the Rails Trac site. You can see if any of the core developers will see why converting a decimal to an integer is completely counter intuitive.

Popular posts from this blog

Lists and arrays in Dart

Converting Array to List in Scala

Null-aware operators in Dart