Skip to content

Instantly share code, notes, and snippets.

@fellix
Created December 6, 2011 13:32
Show Gist options
  • Select an option

  • Save fellix/1438215 to your computer and use it in GitHub Desktop.

Select an option

Save fellix/1438215 to your computer and use it in GitHub Desktop.
Mongoid Money Field
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
@fellix
Copy link
Author

fellix commented Dec 6, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment