Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Remove composed_of example in README #179

merged 1 commit into from

3 participants


This replaces the composed_of example in the README with accessor definitions that accomplish the same task.



This pull request passes (merged a66ddfa into 4facf60).

@semmons99 semmons99 merged commit 2178526 into RubyMoney:master

Awesome. Merged!


@hakanensari would you update the wiki with this information too?


@semmons99 no worries, I've done that already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 24, 2012
  1. @hakanensari
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 20 deletions.
  1. +12 −20
@@ -231,36 +231,28 @@ implementations.
## Ruby on Rails
-To integrate money in a rails application use [money-rails](
+To integrate money in a Rails application use [money-rails](
gem or follow the instructions below.
-Use the `composed_of` helper to let Active Record deal with embedding the money
+Define accessor methods to let Active Record deal with embedding the money
object in your models. The following example requires 2 columns:
``` ruby
:price_cents, :integer, :default => 0, :null => false
-:currency, :string
+:price_currency, :string
Then in your model file:
``` ruby
-composed_of :price,
- :class_name => "Money",
- :mapping => [%w(price_cents cents), %w(currency currency_as_string)],
- :constructor => { |cents, currency| || 0, currency || Money.default_currency) },
- :converter => { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") }
-For Money 2.2.x and previous versions, simply use the following `composed_of`
+def price
+ price_cents || 0, price_currency || Money.default_currency
-``` ruby
-composed_of :price,
- :class_name => "Money",
- :mapping => [%w(price_cents cents), %w(currency currency)],
- :constructor => { |cents, currency| || 0, currency || Money.default_currency) }
+def price=(value)
+ Money.parse(value).tap do |price|
+ write_attribute :price_cents, price.cents
+ write_attribute :price_currency, price.currency_as_string
+ end
-Note the difference in the currency column mapping (currency_as_string vs. currency) - this matters! For further details read the full discussion
Something went wrong with that request. Please try again.