[Rails] Looping through all models in the application

Henning Kilset Pedersen henning at mopo.no
Thu Jan 5 10:34:21 GMT 2006


Hello.

I have an application that depends on a table/model 
(ModelInternationalization) that provides international translations in 
various languages for all the model/table and columns names as well as 
some other stuff (whether the column is visible on forms, dropdowns, 
lists, reports etc).

I need to create a management interface for this translation stuff (the 
plaintext stuff, btw, will be handled by GetText). To do this, I need to 
loop through all the models in the application and check if they are 
present for the currently selected language in the translation model. 
Maybe some pseudocode would help clarify

for m in Application models
    <%= h m.model.name %>
end

Essentially, this would loop through all the models available to the 
application and just display it's name. Ofcourse, the actually code is 
much more complex.

Is there a collection of the available models somewhere? Or do I need to 
goof it up and just parse the directory listing of the app/models 
directory? Or worse, create a table with just the names of the models 
and loop through that?

Regards,
Henning Pedersen



More information about the Rails mailing list