errors about aggregation

Hey there

i dont quite know the change of rails 2.0 , but according to Agile
Development With Rails, aggregation seem not working....i now create a
class like this

Hey there

i dont quite know the change of rails 2.0 , but according to Agile
Development With Rails, aggregation seem not working....i now create a
class like this
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Temp
attr_reader :n, :stuck_out_tongue:

def initialize(n,p)
   @n = n
   @p = p
end

def to_s
   [@n,@p].compact.join(",")
end
end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
now i create a class using ActiveRecord to save to Database, it looks
like this:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def User<ActiveRecord::Base
#next line NO.17
composed_of( :attr, :class_name=>Temp, :mapping=>[[:name , :n],

:class_name should be the name, ie :class_name => 'Temp'
Also make sure that your Temp class is in temp.rb

[:password , :p]])

temp = Temp.new("abc","abc")
User.create(:attr=> temp)
end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
the problem is some ERROR prompt up :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/
dependencies.rb:478:in `const_missing': uninitialized constant
User::Temp (NameError)
  from test.rb:17
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
which indicates the <compose_of> method to be mistaken , i check the
rails API, but the the LATEST rails API is 2007 Dec on http://www.rubyonrail.com
, is the API Rails 1.X ? Have not updated to rails 2.0 yet?

Dec 2007 is when rails 2.0 came out.

You just need modify this line

:mapping=>[[:name , :n], [:password , :p]]

to

:mapping => [[“name” , “n”], [“password” , “p”]]

not working my friend , still the same error

it's all in one test.rb before , now the Temp class has moved to
temp.rb , but still some errors ,why?

Can you show us all of your Temp class please, and the code that you’re using to get that error, and any other model that defines a relationship with the Temp class. It looks possible to me that you’re doing :class_name => Temp, when it should be :class_name => “Temp”. I think that’s where I recall getting an error message like that from.

okay

this is temp.rb

Yup, just as I thought!

composed_of :attr, :class_name=>Temp, :mapping=>[[:name , :n],
[:password , :p]]

This should be :class_name=>“Temp”, and then it may work after that.

May I ask, what are you trying to achieve with this code? It doesn’t seem very Railsy.

sorry to say , that still not right after changing

Where are you calling sort? It’s pointing to line 19 in your test.rb, which looks to me to be the call to create.

Ok, do you want to make this more railsy? Your models don’t appear to be in a rails directory at all, and the way you are establishing the connection and defining the model in the same file is not very neat. I suggest reading through a Rails tutorial, I’ve begun to write a large one myself and that should kick start you on the path to enlightenment: http://frozenplague.net/forum-guide-getting-started/ Just click through the pages in the right menu, they are in the proper order, ignoring the Frequently Asked Questions and Lovely People pages.

in fact I just create a ruby project , include all the lib files ,
assuming same as a rails project and start my code.

finally, as Erik the Archangel said , i also change the mapping part ,
i works now , thank you very much for your help

No that’s not how you create a Rails app. You have to firstly generate the skeleton for the rails app. Read through the tutorial, it should teach you a few things.