An ActiveRecord plugin to use price fields stored in cents as dollars.
Requires Money gem. (Tested with version 2.1.5)
script/plugin install git://github.com/sdbase/in_dollars.git
Given there is an 'awesomes' table with 'price' and 'cost' integer columns:
class Awesome < ActiveRecord::Base in_dollars :price, :cost end awesome = Awesome.new awesome.price = 10000 awesome.price_in_dollars # => 100.00 awesome.price_in_dollars = 50.00 awesome.price # => 5000 awesome.cost = 5000 awesome.cost_in_dollars # => 50.00 awesome.cost_in_dollars = 25.00 awesome.cost # => 2500
You can pass any arguments to *_in_dollars that you would to Money#format:
awesome.price_in_dollars(:symbol => true) # => $50.00
Copyright (c) 2009 sdbase, released under the MIT license