# errors about aggregation

**URL:** <https://discuss.rubyonrails.org/t/errors-about-aggregation/29452>\
**Category:** rubyonrails-talk\
**Created:** [May 16, 2008, 9:53am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452 "2008-05-16T09:53:32Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![stone](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@stone](https://discuss.rubyonrails.org/u/stone)\
**Post date:** [May 16, 2008, 9:53am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/1 "2008-05-16T09:53:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [May 16, 2008, 9:57am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/2 "2008-05-16T09:57:09Z")

</div>

> 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, 😛
> 
> def initialize(n,p) &nbsp;&nbsp;&nbsp;@n = n &nbsp;&nbsp;&nbsp;@p = p end
> 
> def to\_s &nbsp;&nbsp;&nbsp;[@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) &nbsp;&nbsp;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](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.

---

<div class="post-metadata">

**Author:** ![Eric\_Archangel](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@Eric\_Archangel](https://discuss.rubyonrails.org/u/Eric_Archangel)\
**Post date:** [May 16, 2008, 10:58am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/3 "2008-05-16T10:58:25Z")

</div>

You just need modify this line

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

to

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

---

<div class="post-metadata">

**Author:** ![stone](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@stone](https://discuss.rubyonrails.org/u/stone)\
**Post date:** [May 19, 2008, 5:04am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/4 "2008-05-19T05:04:56Z")

</div>

not working my friend , still the same error

---

<div class="post-metadata">

**Author:** ![stone](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@stone](https://discuss.rubyonrails.org/u/stone)\
**Post date:** [May 19, 2008, 5:35am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/5 "2008-05-19T05:35:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![radar](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/radar/32/604_2.png) [@radar](https://discuss.rubyonrails.org/u/radar)\
**Post date:** [May 19, 2008, 5:39am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/6 "2008-05-19T05:39:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stone](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@stone](https://discuss.rubyonrails.org/u/stone)\
**Post date:** [May 19, 2008, 5:50am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/7 "2008-05-19T05:50:43Z")

</div>

okay

this is temp.rb

---

<div class="post-metadata">

**Author:** ![radar](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/radar/32/604_2.png) [@radar](https://discuss.rubyonrails.org/u/radar)\
**Post date:** [May 19, 2008, 5:54am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/8 "2008-05-19T05:54:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stone](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@stone](https://discuss.rubyonrails.org/u/stone)\
**Post date:** [May 19, 2008, 6:13am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/9 "2008-05-19T06:13:32Z")

</div>

sorry to say , that still not right after changing

---

<div class="post-metadata">

**Author:** ![radar](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/radar/32/604_2.png) [@radar](https://discuss.rubyonrails.org/u/radar)\
**Post date:** [May 19, 2008, 6:20am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/10 "2008-05-19T06:20:21Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![stone](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@stone](https://discuss.rubyonrails.org/u/stone)\
**Post date:** [May 19, 2008, 6:29am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/11 "2008-05-19T06:29:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stone](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@stone](https://discuss.rubyonrails.org/u/stone)\
**Post date:** [May 19, 2008, 6:38am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/12 "2008-05-19T06:38:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![radar](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/radar/32/604_2.png) [@radar](https://discuss.rubyonrails.org/u/radar)\
**Post date:** [May 19, 2008, 6:57am UTC](https://discuss.rubyonrails.org/t/errors-about-aggregation/29452/13 "2008-05-19T06:57:18Z")

</div>

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.
