[Rails] Unable to get the domain in my routes.rb to map
customroute tables per domain
Nathaniel S. H. Brown
nshb at inimit.com
Sun Jan 1 01:22:04 GMT 2006
I have two domains setup on my rails app:
example.COM and example.NET
I want to be able to have a case in the routes, that if the URL in the
location bar is example.NET to use this route:
if hostname.match(/NET/)
map.connect '', :controller => 'special', :action => 'case'
else
map.connect '', :controller => 'default', :action => 'index'
End
That way I can have a new root URL for example.NET, but use the same
application.
This should definitely be available as it is available through the
@request.domain(1) within the view. Question is, if its not available in a
default variable, how can I populate it manually? I checked out the CGI
module from Ruby, and it mentions to use the ENV['HTTP_HOST'] variable, but
that is empty. So I am led to believe that Rails gets the active domain
through some other mechanism, yet I am unable to find where this is done.
Thanks.
-Nb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Nathaniel S. H. Brown http://nshb.net
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> -----Original Message-----
> From: rails-bounces at lists.rubyonrails.org
> [mailto:rails-bounces at lists.rubyonrails.org] On Behalf Of
> Ezra Zygmuntowicz
> Sent: December 31, 2005 12:03 PM
> To: rails at lists.rubyonrails.org
> Subject: Re: [Rails] Unable to get the domain in my routes.rb
> to map customroute tables per domain
>
> Nathaniel-
>
> I don't think you are going to be able to do this in
> routes. I could be wrong but I dont think the request obje3ct
> is available to routes in the way that you want. I think its
> more likely that you could use a before filter in
> application.rb to do a redirect to the correct url based on
> the subdomain. But I could be misunderstanding what you are
> trying to do. Any more details of what you want to accomplish?
>
> Cheers-
> -Ezra
>
>
> On Dec 30, 2005, at 11:12 PM, Nathaniel S. H. Brown wrote:
>
> > I am still struggling with this. Anyone able to point me in
> the right
> > direction?
> >
> > -Nb
> >
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Nathaniel S. H. Brown http://nshb.net
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> >
> >> -----Original Message-----
> >> From: rails-bounces at lists.rubyonrails.org
> >> [mailto:rails-bounces at lists.rubyonrails.org] On Behalf Of
> Nathaniel
> >> S. H. Brown
> >> Sent: December 30, 2005 5:01 AM
> >> To: rails at lists.rubyonrails.org
> >> Subject: [Rails] Unable to get the domain in my routes.rb to map
> >> custom route tables per domain
> >>
> >> I have tried all night trying to find a way to get the host name
> >> which is currently being used within my routes.rb file to do some
> >> case/when switching for specific domains such as this
> >>
> >> cgi = ActionController::CgiRequest.new(CGI.new)
> >> case cgi.domain(1)
> >> when /www/
> >> map.connect '', :controller =>
> >> 'public', :action => 'index'
> >> when /internal/
> >> map.connect '', :controller => 'admin',
> :action => 'index'
> >> end
> >>
> >> And have had no success. The domain(1) is empty in this case.
> >>
> >> I have tried a similar approach in one of my views, using the
> >> @request.domain(1) and that works PERFECT. Yet I have
> found no way to
> >> access the same @request.domain(1) within my routes.rb as the
> >> @request object has not been loaded yet.
> >>
> >> One thought was to use the ENV['HTTP_HOST'] variable, but with my
> >> current LIGHTTPD setup, I do not have this environment variable
> >> around.
> >>
> >> Any help would be greatly appreciated.
> >>
> >> Regards,
> >> Nathaniel.
> >>
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> Nathaniel S. H. Brown http://nshb.net
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>
> >> _______________________________________________
> >> Rails mailing list
> >> Rails at lists.rubyonrails.org
> >> http://lists.rubyonrails.org/mailman/listinfo/rails
> >>
> >
> > _______________________________________________
> > Rails mailing list
> > Rails at lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
> -Ezra Zygmuntowicz
> WebMaster
> Yakima Herald-Republic Newspaper
> ezra at yakima-herald.com
> 509-577-7732
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
More information about the Rails
mailing list