Subdomains, Routing, and Subdirectory Controllers


For reference, this question is similar to “Subdomains, Session Data,
& Routing” posted Oct. 31, 2006. Link:

I would like to set up a subdomain and, using the request_routing
plugin, have requests to that subdomain call corresponding “sub-
controllers” inside a controller module. That way, urls like:

could be routed to call:

Grouped::TargetController#myaction (located in /app/controllers/

I realize one solution would be to use “Option #2” in the referenced
post above and create an action dedicated to parsing the url and
redirecting to the appropriate controller/action. However, I was
wondering if a simpler approach could be taken through the routing
code by doing something along these lines:


map.with_options :conditions => { :subdomain => ‘sub’ } do |sub|
sub.connect ‘:target/:action/:id’, :controller => “sub/:target”

Any help would be greatly appreciated!


Note: The route in the example code should read:

sub.connect ‘:target/:action/:id’, :controller => “grouped/:target”