Simple question for composed_of

Hi All,

Here’s a n00b question for composed_of. In what file do you put the
class that is used for the composed_of?

For example, let’s say that you have the code below:

class Declaration < ActiveRecord::Base
composed_of :amount, :class_name => “Currency”, :mapping =>
%w(amount amount)

class Currency
attr_accessor :round, :decimal, :amount

def initialize(amount)
self.amount = amount
self.round = amount.to_i.to_s[0…-3]
self.decimal = amount.to_i.to_s[-2…-1]


In what file do you put the code for the class Currency? Thanks!

I would put your class Currency in a file under “apps/models/

It should load the file currency.rb file automatically, since it’s in
the models folder.

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