Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Money represented with the Money gem, persistence using Mongoid
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, currency)
def price=(price)
self.price_pence = price.cents
def currency
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.