Agile Web Development

Build it. Launch it. Love it.

Rails Money

A handler for storing money in the database as integers (as cents), but dealing with them as Money Objects.

Usage:

Create your tables with fields named FIELDNAME_in_cents and you will be able to access them as FIELDNAME. ActiveRecord will return Money objects instead of Fixnums.

add_column :products, :price_in_cents, :integer

product = Product.find_first
product.price = 100.00
product.price >> #<Money @cents=10000>

Money objects deal with money-math properly, and convert themselves to strings nicely.

Vitals

Home http://www.nullcreations.net
Repository svn://svn.nullcreations.net/plugins/rails_money
License Rails' (MIT)
Rating (16 votes)
Owner Jerrett Taylor
Created 14 March 2007

Comments

  • Avatar
    JM
    26 November 2007

    Liking this plugin, but it returns zero amounts as "free"... which might be nice if you're only using this plugin to display prices. Could you add an easy way to disable this behavior?

  • JM
    1 January 2008

    Does this plugin working with Rails 2?

  • jt
    28 March 2008

    it should only return free on the to_s method ..

  • jt
    28 March 2008

    shouldn't have any problems with rails 2!

  • Avatar
    k
    15 September 2008

    @JM, Just modify the source.

    Open up vendor/plugins/rails_money/lib/money.rb and change the line

    return "free" if free?

    to

    return "whatever you want" if free?

    Granted, you'd have to do this every time you update the plugin, assuming there are changes, but I bet a clever programmer could find a way to automate all that ;)

  • Avatar
    greg h
    8 November 2008

    how does this relate to the ruby gem "money" that is available?

  • Avatar
    Hackedunit
    14 July 2009

    Can I use this plugin for Pounds and Euros ?

Add a comment