Forum: Rails I18n auto detect URL

Posted by Richard Schneeman (snowmaninthesun)
on 2008-12-12 17:08
Is it possible to read the URL that someone uses to access your site.
For example: I own, www.english.com and www.chinese.com  and only have
one rails site. Is it possible, when a user accessing my rails site from
english.com is automatically set to use my English I18n, as well as a
separate style sheet, where as www.chinese.com would utilize chinese
I18n ??
Posted by Jaime Iniesta (Guest)
on 2008-12-12 17:24
(Received via mailing list)
On Fri, Dec 12, 2008 at 5:08 PM, Richard Schneeman
<thedickster@gmail.com> wrote:
> Is it possible to read the URL that someone uses to access your site.
> For example: I own, www.english.com and www.chinese.com  and only have
> one rails site. Is it possible, when a user accessing my rails site from
> english.com is automatically set to use my English I18n, as well as a
> separate style sheet, where as www.chinese.com would utilize chinese
> I18n ??

Hi Richard, yes it's possible. I have a rails app that can be accessed
from various domains, what I do is check request.host to get the
domain.

--
Jaime Iniesta
http://jaimeiniesta.com
http://www.workingwithrails.com/person/6722-jaime-iniesta
Posted by Richard Schneeman (snowmaninthesun)
on 2008-12-12 20:27
Hey thanks for the heads up!!!

For anyone else who wants to implement this, you can just put

<%= request.host %> in your view or
request.host in your controller

if you are looking at your site from http://0.0.0.0:3000 you will get a 
return of:

0.0.0.0

Thanks Jaime !!
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.