Skip to content

Instantly share code, notes, and snippets.

@sasha-id
Created July 18, 2012 22:08
Show Gist options
  • Save sasha-id/3139231 to your computer and use it in GitHub Desktop.
Save sasha-id/3139231 to your computer and use it in GitHub Desktop.
Money represented with the Money gem, persistence using Mongoid 3
class MoneyField
def mongoize
return if object.nil?
cents
end
class << self
def demongoize(object)
return nil unless object
Money.new(object)
end
def mongoize(object)
Money.parse(object).cents
end
def evolve(object)
Money.parse(object).cents
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment