Skip to content

Ruby on Rails (Money.gem 2.2.* and earlier)

semmons99 edited this page Apr 9, 2012 · 1 revision

When using Money.gem 2.2.* and earlier you can use the following with ActiveRecord.

Use the #composed_of helper to let ActiveRecord deal with embedding the money object in your models. The following example requires a cents and a currency field.

composed_of :price,
  :class_name => "Money",
  :mapping => [%w(cents cents), %w(currency currency)],
  :constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) }