Forum: Ruby on Rails Subdomains, Routing, and Subdirectory Controllers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
jtcalhoun (Guest)
on 2007-04-01 02:49
(Received via mailing list)
For reference, this question is similar to "Subdomains, Session Data,
& Routing" posted Oct. 31, 2006.  Link:

http://groups.google.com/group/rubyonrails-talk/br...
----

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:

http://sub.example.com/target/myaction

could be routed to call:

Grouped::TargetController#myaction  (located in /app/controllers/
grouped/target_controller.rb)


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:

# match sub.example.com
map.with_options :conditions => { :subdomain => 'sub' } do |sub|
  sub.connect ':target/:action/:id', :controller => "sub/:target"
end

Any help would be greatly appreciated!
jtcalhoun (Guest)
on 2007-04-01 03:09
(Received via mailing list)
Note: The route in the example code should read:

sub.connect ':target/:action/:id', :controller => "grouped/:target"
This topic is locked and can not be replied to.