Hello. I'm adding an admin section to my site and have configured
routing along the following lines:
map.connect 'admin/:controller/:action/:id'
The above works fine. However, if I have controller 'A', it is still
accessible from http://mysite.com/A due to the
default :controller/:action/:id route. I'd rather not have two URIs
mapped to the same page and am wondering if there is a way to exclude
a controller from a route or to alter the path to http://mysite.com/admin/A
when a user visits http://mysite.com/A. As of now, my only solution
is to remove the :controller/:action/:id route, but this means I would
have to map routes for every controller I want accessible at my
webroot which is kind of a pain and doesn't seem very rails like.
The above works fine. However, if I have controller 'A', it is still
accessible from http://mysite.com/A due to the
default :controller/:action/:id route. I'd rather not have two URIs
mapped to the same page and am wondering if there is a way to exclude
a controller from a route or to alter the path to http://mysite.com/admin/A
when a user visits http://mysite.com/A.
you can use the :requirements param of the route, so you can match :controller against a regexp. If the pattern is not matched, then the route will not be recognized for that request