Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Use RubyMoney with mongoid
Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.document
.gitignore
.rspec
.rvmrc
Gemfile
Gemfile.lock
MIT-LICENSE.txt
README.rdoc
Rakefile
VERSION
mongoid_money_field.gemspec

README.rdoc

mongoid money field

This is a super simple gem to use RubyMoney money type columns with mongoid

github.com/RubyMoney/money github.com/mongoid/mongoid

Description

A simple gem that creates a Money datatype using RubyMoney for Mongoid.

Inspired by gist.github.com/840500

Updating

v2.0 breaks compatibility as it does not give 0 cents default anymore. Use

money_field_with_options :price, default: 0

instead

Installation

Include the gem in your Gemfile

gem 'mongoid_money_field'

Usage

class DummyMoney
  include Mongoid::Document
  include Mongoid::MoneyField

  field :description

  money_field :price, :old_price

  # to disallow changing currency (and to not store it in database)
  money_field_with_options :price2, fixed_currency: 'GBP'

  # set a default
  money_field_with_options :price3, default: '1.23 RUB'
end

All Money values are converted and stored in mongo as cents and currency in two separate fields.

Finding by price

DummyMoney.where(price_cents: 123).first

Copyright

Copyright © 2012 glebtv. MIT License.

Something went wrong with that request. Please try again.