Money library usage?

I’m obviously doing something stupid, but I’m trying to figure out how
the Money library ( is supposed to
work. I have a Product model and I want to have an attribute in my
model called “price” and I want it to accept Money objects.

So I have this in my Product model.

class Product < ActiveRecord::Base
	composed_of :price, :class_name => 'Money'

From what I can tell, I should be able to do:

p =
p.price =

and have the price return a Money object?

I can’t get this to work. What am I doing wrong? Is this how Money is
supposed to work?

Thanks for any help,

Hi !

2006/6/25, Jordan E. [email protected]:

    class Product < ActiveRecord::Base
            composed_of :price, :class_name => 'Money'

You’re only missing the mapping:

composed_of :price, :class_name => ‘Money’, :mapping => %w(price cents)

Hope that helps !

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs