Hi,
I’m getting this error:
p = Plan.new
p.amount
TypeError: wrong argument type String (expected Fixnum)
Apparently this happens because the aggregation isn’t initialized.
Here’s the code:
class Plan < ActiveRecord::Base
composed_of :amount,
:class_name => “Money”,
:converter => Proc.new { |s| Money.new(s) },
:mapping => [:price, :value]
end
class Money
attr_reader :value
def initialize(string)
@value = BigDecimal(string.sub(/,/, ‘.’))
end
def to_s
Integer(@value * 100).to_s.sub(/(\d{2})$/, ‘,\1’)
end
end
I would like to hide the aggregation from controllers…
There’s the after_initialization callback where I could (try to)
initialize the value object if it is nil…
I wonder what’s the proper way to deal with this situation?
Thanks,
–
Adriano