Forum: Ruby on Rails Domain Requirements in Routes (Edge Rails)

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.
Ff86e52a9c4e1d5b42f11f5f0bb458c6?d=identicon&s=25 Ben Blakley (brblakley)
on 2006-03-23 22:00
I saw on the bottom of the following page that you can route requests to
different controllers based upon which subdomain is being requested.

http://wiki.rubyonrails.com/rails/pages/Routes

with_options :requirements=>{:subdomain=>'first.com'} do
    map.connect '', :controller => "first/catalog"
    map.connect 'featured', :controller => "first/catalog",
:action=>'featured'
    map.connect 'catalog/:action/:id', :controller => "first/catalog"
end

So you could have one home page setup for one subdomain and another home
page for another subdomain. I've tried implementing this with Edge
Rails, but haven't had any luck. The :subdomain requirement doesn't seem
to have any affect. I must be missing something. I've looked through the
Edge Rails documentation and haven't seen anything that talks about
using :subdomain. Does the domain or subdomain need to be passed into
the routes somehow? Any help would be appreciated.
Ff86e52a9c4e1d5b42f11f5f0bb458c6?d=identicon&s=25 Ben Blakley (brblakley)
on 2006-03-23 22:48
I just noticed what looks like an error in the code on the Wiki. I think
it should be:

map.with_options :requirements=>{:subdomain=>'first.com'} do |m|
    m.connect '', :controller => "first/catalog"
    m.connect 'featured', :controller => "first/catalog",
:action=>'featured'
    m.connect 'catalog/:action/:id', :controller => "first/catalog"
end

Although this still doesn't seem to help with the :subdomain
requirement.
5810a1b7743eb2186ca0ea1d0a3469a0?d=identicon&s=25 Stephen Bannasch (Guest)
on 2006-03-24 06:59
(Received via mailing list)
I'm running Rails 1.1 RC1 and Webbrick reports a Content-Length: 0
for any dynamic content it delivers. When I serve static content
(like images) the Content-Length is calculated correctly.

I'm trying to track down an obscure bug and this is one difference
bewteen a system that is working and one that isn't.

curl  -I http://localhost:3000/page/otml/1
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Keep-Alive
Date: Fri, 24 Mar 2006 05:45:16 GMT
Content-Type: text/xml; charset=UTF-8
Server: WEBrick/1.3.1 (Ruby/1.8.4/2005-12-24)
Content-Length: 0
Set-Cookie: _session_id=109456392dcb2d36dbd500ee5d3ddb1f; path=/

The actual Content-Length is 8620.
A7a7500626778d47f8fd974f5564cf3e?d=identicon&s=25 Ross Karchner (Guest)
on 2006-03-27 05:57
(Received via mailing list)
Has anyone seen  :requirements=>{:subdomain=>whatever} in the wild? Is
it documented anywhere other than that wiki page?

On 2006-03-23 16:48:31 -0500, Ben Blakley
<ben@reussnewmedia.com> said:
0f5718dee13e20d0eff7952358de2f8e?d=identicon&s=25 Adrian Liem (adrianliem)
on 2006-09-10 17:47
yeah i've post the problem on the railsforum.com previously but noone
answered that yet. i'm frustrated
F641ba2e0fc906fb77d74b52cf59d187?d=identicon&s=25 Doug Dupory (doug)
on 2006-09-10 20:19
Frustration no more. See the Request Routing plugin. With the new
routing code, it's almost too easy!
http://agilewebdevelopment.com/plugins/request_routing

Ben Blakley wrote:
> I saw on the bottom of the following page that you can route requests to
> different controllers based upon which subdomain is being requested.
>
> http://wiki.rubyonrails.com/rails/pages/Routes
>
> with_options :requirements=>{:subdomain=>'first.com'} do
>     map.connect '', :controller => "first/catalog"
>     map.connect 'featured', :controller => "first/catalog",
> :action=>'featured'
>     map.connect 'catalog/:action/:id', :controller => "first/catalog"
> end
>
> So you could have one home page setup for one subdomain and another home
> page for another subdomain. I've tried implementing this with Edge
> Rails, but haven't had any luck. The :subdomain requirement doesn't seem
> to have any affect. I must be missing something. I've looked through the
> Edge Rails documentation and haven't seen anything that talks about
> using :subdomain. Does the domain or subdomain need to be passed into
> the routes somehow? Any help would be appreciated.
0f5718dee13e20d0eff7952358de2f8e?d=identicon&s=25 Adrian Liem (adrianliem)
on 2006-09-11 06:38
i've installed the Request Routing plugin from that URL, but it does not
seem to work on my application. the :requirements still does not have
any effect. i can get the subdomain name with the SubdomainAsAccountKey
plugin, but the subdomain routing can't work. :(

i need subdomain routing to map this:
URL> admin.domain.com/setting    # :controller=>'admin',
:action=>'setting'
URL> username.domain.com/setting # :controller=>'user',
:action=>'setting'

thanks in advance

Doug Dupory wrote:
> Frustration no more. See the Request Routing plugin. With the new
> routing code, it's almost too easy!
> http://agilewebdevelopment.com/plugins/request_routing
0727907ae68db2e8ebc1ea1b01f00d69?d=identicon&s=25 Dan Webb (Guest)
on 2006-09-11 17:20
(Received via mailing list)
> i've installed the Request Routing plugin from that URL, but it does not
> seem to work on my application. the :requirements still does not have
> any effect. i can get the subdomain name with the SubdomainAsAccountKey
> plugin, but the subdomain routing can't work. :(
>

In the new version of Rails you need to use :conditions rather than
:requirements

Also, request routing just specifies a requirement for routing.  EG.
you can say things like only use these routes if the subdomain is not
admin or whatever so it might not actually be the answer to your
problem but in this case it looks like it will work.

Cheers,

--
Dan Webb
http://www.danwebb.net
0f23274e975611727e4ad46d745d298e?d=identicon&s=25 Bill (Guest)
on 2006-09-11 17:55
Dan Webb wrote:
>> i've installed the Request Routing plugin from that URL, but it does not
>> seem to work on my application. the :requirements still does not have
>> any effect. i can get the subdomain name with the SubdomainAsAccountKey
>> plugin, but the subdomain routing can't work. :(
>>
>
> In the new version of Rails you need to use :conditions rather than
> :requirements
>
> Also, request routing just specifies a requirement for routing.  EG.
> you can say things like only use these routes if the subdomain is not
> admin or whatever so it might not actually be the answer to your
> problem but in this case it looks like it will work.
>
> Cheers,
>
> --
> Dan Webb
> http://www.danwebb.net


I just dealt with this use this morning.  I found the info in the README
with the plugin.  I forget if there are other changes.
0f5718dee13e20d0eff7952358de2f8e?d=identicon&s=25 Adrian Liem (adrianliem)
on 2006-09-12 04:57
wow it works
apperently i haven't read the Readme file for the recent changes. i read
the old manual from somewhere on the web.
thanks Dan, you rocks :)

it works when i tried this:

map.connect 'setting', :controller => 'admin', :action => 'setting',
:conditions => { :subdomain => 'admin' }
map.connect 'setting', :controller => 'user', :action => 'setting',
:conditions => { :subdomain => 'user' }

but it fail when previously i tried this:

map.with_options :conditions=>{:subdomain=>'admin'} do |map|
  map.connect 'setting', :controller => 'admin', :action => 'setting'
end
map.with_options :conditions=>{:subdomain=>'user'} do |map|
  map.connect 'setting', :controller => 'user', :action => 'setting'
end
map.with_options :conditions=>{:subdomain=>'test'} do |map|
  map.connect 'setting', :controller => 'test', :action => 'setting'
end

the user subdomain generates 'Recognition failed for "/setting"'. i
tried to add the test subdomain, and it generates the same error
message. did i missed something? it's ok though, i still can the without
with_options version :)

and somehow, i cannot connect to controller when i put an empty string
to the map connect, it still connect to the main index. any suggestion?

map.connect '', :controller => 'admin', :action => 'index', :conditions
=> { :subdomain => 'admin' }
map.connect '', :controller => 'user', :action => 'index', :conditions
=> { :subdomain => 'user' }

thanks,

Adrian Liem


Dan Webb wrote:
> In the new version of Rails you need to use :conditions rather than
> :requirements
>
> Also, request routing just specifies a requirement for routing.  EG.
> you can say things like only use these routes if the subdomain is not
> admin or whatever so it might not actually be the answer to your
> problem but in this case it looks like it will work.
>
> Cheers,
>
> --
> Dan Webb
> http://www.danwebb.net
This topic is locked and can not be replied to.