# Acts\_as\_tree without database

**URL:** <https://www.ruby-forum.com/t/acts-as-tree-without-database/117080>\
**Category:** Rails\
**Created:** [October 12, 2007, 7:35pm UTC](https://www.ruby-forum.com/t/acts-as-tree-without-database/117080 "2007-10-12T19:35:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wogri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/edb3f5/32.png) [@wogri](https://www.ruby-forum.com/u/wogri)\
**Post date:** [October 12, 2007, 7:35pm UTC](https://www.ruby-forum.com/t/acts-as-tree-without-database/117080/1 "2007-10-12T19:35:29Z")

</div>

Hi,

I’m currently developing a web-application that is multilingual. I’m  
using ruby+gettext for the multilingual facility. Now I’d like to  
create a category view that acts\_as\_tree, but with multilingual :name-  
values.  
My ideal solution would be to not bind that category-model to the  
database, because the categories are just 50 or so, which won’t be  
updated dynamically. So I’d like to act that model as a tree, but fill  
in the data at class-instantiation time.

like so:

Class Category \< ActiveRecord::Base

acts\_as\_tree  
attr :name  
attr :parent\_id  
attr :id

def initialize  
fill\_the\_data  
end

Can anybody help? Is this possible at all? My guess is “no”, but I’ll  
wait for your replies, guys.

Regards,  
wogri

---

<div class="post-metadata">

**Author:** ![wogri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/edb3f5/32.png) [@wogri](https://www.ruby-forum.com/u/wogri)\
**Post date:** [October 12, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/acts-as-tree-without-database/117080/2 "2007-10-12T19:50:07Z")

</div>

But what would be wrong with binding it to the database? You could  
have the database populated in the migration, so that you don’t forget  
to do it or anything. If you really want to make sure your categories  
table is protected, you could override the class’s save method,  
destroy method, etc.  
-Nathan

---

<div class="post-metadata">

**Author:** ![wogri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/edb3f5/32.png) [@wogri](https://www.ruby-forum.com/u/wogri)\
**Post date:** [October 12, 2007, 7:58pm UTC](https://www.ruby-forum.com/t/acts-as-tree-without-database/117080/3 "2007-10-12T19:58:20Z")

</div>

On Oct 12, 7:49 pm, removed\_email\_address@domain.invalid wrote:

> But what would be wrong with binding it to the database? You could  
> have the database populated in the migration, so that you don’t forget  
> to do it or anything.

There’s nothing wrong with binding it to the DB, but it doesn’t work  
with gettext, AFAIK. I want ONE central translation for my application  
with the po-files of gettext.

wogri

---

<div class="post-metadata">

**Author:** ![wogri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/edb3f5/32.png) [@wogri](https://www.ruby-forum.com/u/wogri)\
**Post date:** [October 12, 2007, 8:34pm UTC](https://www.ruby-forum.com/t/acts-as-tree-without-database/117080/4 "2007-10-12T20:34:37Z")

</div>

Oh, I see. Sorry, didn’t read properly. I’ve asked a question just  
before you did about abstract\_class. My question more or less asks if  
setting self.abstract\_class to true does what you want it to do  
(although I’m doing it for a slightly different purpose). Nobody’s  
answered yet though. But have a look into that. Otherwise, you could  
overwrite all the database interaction methods for that class to  
prevent throwing exceptions, and have self.columns = [].

---

<div class="post-metadata">

**Author:** ![wogri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/edb3f5/32.png) [@wogri](https://www.ruby-forum.com/u/wogri)\
**Post date:** [October 12, 2007, 10:24pm UTC](https://www.ruby-forum.com/t/acts-as-tree-without-database/117080/5 "2007-10-12T22:24:04Z")

</div>

On Oct 12, 8:33 pm, removed\_email\_address@domain.invalid wrote:

> Oh, I see. Sorry, didn’t read properly. I’ve asked a question just  
> before you did about abstract\_class. My question more or less asks if  
> setting self.abstract\_class to true does what you want it to do  
> (although I’m doing it for a slightly different purpose). Nobody’s  
> answered yet though.

Thanks for your reply again;  
I’ve solved it in the mean time by saving the english data in the  
database, loading it, running the names through a “translation-hash”,  
and re-sorting the translated names. Quite expensive, but I couldn’t  
think of any better in that short time;

wogri
