Routing for grouping controllers and avoid modules

Juanma Cervera пишет:

Hello,
I have this code in my config/routes.rb file

ActionController::Routing::Routes.draw do |map|
  map.supervisor 'supervisor/:controller/:action/:id'
  map.connect ':controller/:action/:id'
end

I try to group three or four controlles in the same URL path with routing, avoinding the use of modules or controller namespaces.
All the other controllers will have an standard rails URL, matching the last route.
  

I would do like this :

ActionController::Routing::Routes.draw do |map|
  ['foo', 'bar', 'baz'].each do |supervisor_controller|
    map.connect "/supervisor/#{supervisor_controller}/:action/:id", :controller => supervisor_controller
  end
  map.connect ':controller/:action/:id'
end

Doing like that you have explicitly stated set of controllers that can be mapped to by those urls. + no need to change any other logic or use named routes.

Also, I wouldn't leave CAPTURE_EM_ALL route at (the one at the end).

I'm a bit fear of controllers in modules, because you need to use link_to with caution (haven't you forgot to prefix all your controllers with "/" in link_to params ?)