Created
July 18, 2012 22:08
-
-
Save sasha-id/3139231 to your computer and use it in GitHub Desktop.
Money represented with the Money gem, persistence using Mongoid 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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