Created
December 6, 2011 13:32
-
-
Save fellix/1438215 to your computer and use it in GitHub Desktop.
Mongoid Money Field
This file contains hidden or 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
| module Mongoid | |
| class MoneyField | |
| include Mongoid::Fields::Serializable | |
| def deserialize(object) | |
| return nil unless object | |
| Money.new(object) | |
| end | |
| def serialize(object) | |
| return object.to_money.cents if object.respond_to?(:to_money) | |
| Money.new(object.to_i).cents | |
| end | |
| end | |
| end | |
| # see https://github.com/RubyMoney/money |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dependency https://github.com/RubyMoney/money