Re: getting all controllers for application

Florian Groß
Tue, 10 May 2005 23:00:44 -0000

Craig Beck wrote:

> The question is there any way of doing this automatically (kinda like
> AR extracts columns and db schema) from the application so that I  could
> modify the application.rhtml once with something like <%=
> get_all_controllers_as_links %> and have it automatically keep up  with
> newly added controllers etc?

I''m not sure if there is a simpler way of doing it, but this ought to
work:

def all_controllers()
   result = []

   ObjectSpace.each_object(Class) do |cls|
     if cls < ApplicationController then
       result << cls
     end
   end

   return result
end