Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Money represented with the Money gem, persistence using Mongoid

View mongoid_money_usage.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
class Product
include Mongoid::Document
include Mongoid::Timestamps
 
field :description, :type => String
field :price_pence, :type => Integer, :default => 0
field :currency_iso, :type => String, :default => Money.default_currency.iso_code
validates_presence_of :description
validates_numericality_of :price_pence
# Virtual price / currency attributes
def price
Money.new(self.price_pence, currency)
end
def price=(price)
self.price_pence = price.cents
end
 
def currency
Money::Currency.new(currency_iso)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.