This project is archived and is in readonly mode.

#3387 ✓resolved
Sam Ruby

Decimal attributes no longer work on Rails 3.0 edge

Reported by Sam Ruby | October 17th, 2009 @ 10:01 PM | in 3.0.2

Specifically, the following commit does not handle decimals: http://github.com/rails/rails/commit/f936a1f100e75082081e782e5cceb2...

More detail, in the Depot application in AWDwR3, price is defined as:

#<ActiveRecord::Type::Number:0x7fb12389fba8 @typecaster=#<ActiveRecord::ConnectionAdapters::SQLiteColumn:0x7fb1238b93a0 @sql_type="decimal(8,2)", @precision=8, @primary=false, @type=:decimal, @limit=8, @default=#<BigDecimal:7fb1238b90a8,'0.0',9(18)>, @null=true, @name="price", @scale=2>

Decimal is not handled in NumberTest or Type::Number.

The net result is that instead of this value begin converted to a BigDecimal, it is left as a String, resulting in errors like comparison of String with Float failed in validation routines such as:

def price_must_be_at_least_a_cent
  errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.00
end

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages