Using subdomain names in routes?

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