Incorrect composed_of I think

I am trying to use composed_of in my model, but I not succeeding.

With the code I pasted below, I cannot perform this action in the
console:

property = Property.new(1, “px”)

I get NameError: uninitialized constant Property when I try to perform
that action. It’s not finding my class I made I suppose. The Property
class is in the same file as the Element class, element.rb.

Does anyone know how to do this?

Thanx for any and all info.

Code…

My model is simple:

class Element < ActiveRecord::Base
composed_of :fontsize,
:class_name => “Property”,
:mapping =>
[
%w(font_size amount),
%w(font_size_unit unit)
]
end

My class for this is simple:

class Property
attr_reader :amount, :unit

def intialize(amount, unit)
@amount = amount
@unit = unit
end

def to_s
@amount.to_s + @unit
end
end

://
Nathan H.

On 2006-07-13 14:23:52 -0400, Nathan H.
[email protected] said:

I am trying to use composed_of in my model, but I [am] not succeeding.

I have learned, through trial and error, that when using composed_of,
the class belongs in it’s own file.

Example:

element.rb

class Element < ActiveRecord::Base
composed_of :fontsize,
:class_name => “Property”
end

so you would create property.rb and have something like this inside

class Property
attr_reader :amount, :unit

def initialize(amount, unit)
@amount = amount
@unit = unit
end

def to_s
@amount.to_s + @unit
end
end

Just in case anyone needs this info.

://
Nathan H.