Forum: Ruby on Rails Using subdomain names in routes?

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.
Matt Jankowski (Guest)
on 2006-01-17 03:01
(Received via mailing list)
Scenario...

We want to use the name field of our Market object for URLs like...

foo.example.com/groups/view/groupname
bar.example.com/groups/view/groupname

...and other similar URLs, basically using the subdomain as a key for
the app to know which Market (there is a markets table where the
subdomain field corresponds to Market.name) to use.  In this example,
both pages are viewing the group homepage for 'groupname' group.  There
could conceivably be a group called 'groupname' in both the 'foo' and
'bar' market.  We COULD use /group/view/id, but using the name makes me
happier.

I'm aware of using filters in application.rb to use the subdomain as a
key, and I could then access @market throughout the app to figure out
where I am, but it would also be nice to have some rule that sends all
URLs that have a subdomain to a 'markets' controller, for example.

Does this make sense?  I think the basic question is can you do things
with subdomains in routing, instead of just using the filter in
application.rb to set variables that your controllers handle?...

-Matt
This topic is locked and can not be replied to.