Simple Subdomain Routing

Hey all,

I hope this is a relitively simple question, but I have not been able to
arrive at a workable solution for myself.

What I’m wanting to do is a very simple pattern match on a subdomain:
www.* forwards to mydomain.com/www_controller

and everything else forwards to mydomain.com/other_controller

The idea is to forward logged in users to username.mydomain.com, but all
the user’s data is stored in a session, so, it doesn’t need to actually
do any database lookups or anything like that based on the subdomain,
only a routing request.

Thanks in advance!
-Luke

This might be useful to you: http://agilewebdevelopment.com/plugins/
request_routing


Benjamin C.
http://www.bencurtis.com/
http://www.tesly.com/ – Collaborative test case management
http://www.agilewebdevelopment.com/ – Resources for the Rails community

@ benjamin:

Thanks so much for the link. I’ve installed the plugin, but I cannot
seem to get it working (yes, I really am that dense).

I have two controllers, ‘site’ and ‘user’. I would like all routs going
to ‘www’ to go to the site controller, and everything else to user,
however, I cannot get the pieces all glued together.

map.connect '', :controller => 'site', :requirements => { :subdomain => 
'www' }

When I test that (at the top of my routes.rb file), I simply get:
Recognition failed for “/”

However, if I tack on the /site to the url (www.localhost:3000/site), I
get exactly what I would expect (the index method).

Any suggestions? I’ve poked around the net for some further
documentation for the plugin, but I haven’t really come across a whole
lot.

Jón Borgþórsson wrote:

It might not be recognizing www as your subdomain because it’s not the
third name. Thus thinking www is your domain and .local to be the
equivalent to .com.
Instead try putting in the host www.localhost.com to your hosts table
and try that.

Oh my goodness! Of course. I think it’s time I take a break from the
computer for a while – maybe my eyes will go un-crossed and I’ll be
able to see straight again.

Thank you so much!!
-LW

It might not be recognizing www as your subdomain because it’s not the
third name. Thus thinking www is your domain and .local to be the
equivalent to .com.
Instead try putting in the host www.localhost.com to your hosts table
and try that.

On 6/21/06, Luke W. [email protected] wrote:

map.connect ‘’, :controller => ‘site’, :requirements => { :subdomain =>
documentation for the plugin, but I haven’t really come across a whole
lot.


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs