Acts_as_tree without database

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

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

On Oct 12, 7:49 pm, [email protected] 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

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 = [].

On Oct 12, 8:33 pm, [email protected] 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

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