Money datatype for Mongoid. Inspired by Ruby Money. Makes handling money simple. Stores the value in the db as cents.
Be aware! This gem currently requires mongoid to be included in your gemfile as such
gem "mongoid", :git => "git://github.com/mongoid/mongoid.git"
due to a type casting bug introduced in Mongoid version 2.0.0. The fix has not been released to rubygems.org yet.
A simple gem that creates a Money datatype for Mongoid.
Include the gem in your Gemfile
gem 'mongoid_money'
Now you can do things in your Mongoid documents like
field :price, :type => Money, :default => 9.99.dollars
or
field :price, :type => Money, :default => 10.dollars
or
field :price, :type => Money, :default => 99.cents
All Money values are converted and stored in mongo as cents.
You can also query against your Money fields. Just do the following:
Item.where(:price => 5.dollars)
or
Item.where(:price.gt => 10.dollars)
Copyright © 2011 Jeff Bozek. See LICENSE.txt for
further details.