Money library usage?

Hi,
I’m obviously doing something stupid, but I’m trying to figure out how
the Money library (http://dist.leetsoft.com/api/money/) 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'
end

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

p = Product.new
p.price = Money.new(1999)

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,
Jord

Hi !

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

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

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