List controllers?

Hi Raileans,

I’m wondering if there’s any way to get a list of all of the valid
controllers in my application. Specifically, I’m doing some funny
dynamic stuff in my routes.rb and wanted to make sure that valid
controllers will always get mapped while things that are not
controllers will go to my other map. I think it would look something
like this in my mind’s eye:

– start snippet –

application.controllers.each do |controller|
map.connect “#{controller.name}/:action/:id”, :controller =>
controller.name
end

map.connect ‘:something’, :controller => ‘something’, :action => ‘show’
map.connect ‘:something/:weird’, :controller => ‘weird’, :action =>
‘show’

– end snippet –

So basically:

  1. Is there a way of getting a list of all valid controllers from my
    routes file?
  2. Am I going about this the wrong way and if so, is there a better way?

Thanks!

-Pawel

On 3/2/06, Pawel S. [email protected] wrote:

Hi Raileans,

I’m wondering if there’s any way to get a list of all of the valid
controllers in my application. Specifically, I’m doing some funny
dynamic stuff in my routes.rb and wanted to make sure that valid
controllers will always get mapped while things that are not
controllers will go to my other map. I think it would look something
like this in my mind’s eye:

I’m going to reply to myself, since after some searching around, I
think I’ve found a better way here:

As described in that article, I’m just going to create a generic
fallback handler to route to my alternates when controller recognition
fails, like the following:

map.connect ‘*path’, :controller => ‘application’, :action =>
‘handle_unrecog’

I’m not sure I like it, since it will put a bunch of stuff I’d rather
have spread across several controllers into a single central one, but
it does seem like a cleaner and more flexible approach.

I never did figure out how to get a list of all controllers - oh well.
This will do just fine. :slight_smile:

-Pawel

On 03/03/06, Pawel S. [email protected] wrote:

I never did figure out how to get a list of all controllers - oh well.

if you are still curious how to do that take a look at user_engine:

http://svn.rails-engines.org/user_engine/trunk/app/models/permission.rb