https://github.com/chip/rails_money
This is merely a copy of the rails_money repo that was deleted. I am not maintaining this repo, but have put it here for project use. A handler for storing money in ActiveRecord objects as integers (as cents), but dealing with them as Money Objects.
https://github.com/chip/rails_money
Last synced: 3 months ago
JSON representation
This is merely a copy of the rails_money repo that was deleted. I am not maintaining this repo, but have put it here for project use. A handler for storing money in ActiveRecord objects as integers (as cents), but dealing with them as Money Objects.
- Host: GitHub
- URL: https://github.com/chip/rails_money
- Owner: chip
- License: mit
- Created: 2008-12-31T23:00:25.000Z (over 17 years ago)
- Default Branch: master
- Last Pushed: 2008-12-31T23:08:23.000Z (over 17 years ago)
- Last Synced: 2025-01-19T22:15:36.520Z (over 1 year ago)
- Homepage:
- Size: 82 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: MIT-LICENSE
Awesome Lists containing this project
README
= Rails Money
Note! This is NOT compatible with the 'money' gem!
A handler for storing money in ActiveRecord objects as integers (as cents), but dealing
with them as Money Objects.
Note: Dividing a money object will return an array of Money objects. This ensures cents
do not go missing.
For example:
>> money = Money.new(10.00)
=> #
>> money / 3
=> [#, #, #]
All other operations (+, -, *, and Comparable stuff) will work without any surprises or magic.
== Installation
./script/plugin install svn://svn.nullcreations.net/plugins/rails_money
== 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 >> #
Creating a Money can be done from a Fixnum (dollars) or a Float (dollars.cents). To create a money
object from just cents, do Money.create_from_cents(100)
== Feedback
Any suggestions, fixes, or improvements - lemme know, jerrett at gmail