Get server url

Hi all,

How do i get the server url? Much like the PHP function
$_SERVER[“REQUEST_URI”]

Regards,
Stijn

On 10/3/07, Tarscher [email protected] wrote:

Hi all,

How do i get the server url? Much like the PHP function
$_SERVER[“REQUEST_URI”]

You can get it your controller through

request.request_uri

or in your view through

controller.request.request_uri

All the CGI-style variables are available through request.env as well,
so this works:

request.env[‘REQUEST_URI’]

But I wonder why you want it? You normally work with the Rails routing
system and don’t deal with the details of the request URI. What are
you trying to accomplish?

Many thanks for the fast reply.

The request.env[‘REQUEST_URI’] only returns the path eg:
http://localhost:3000/user I get /user . Iactually want
http://localhost:3000/
I can do this via request.protocol()+request.request_uri() but I
wonder if there is a single method that can do this.

I need this for mail sending. I’m creating a user activation system
that wan run on multiple domains. When I send out a mail the user has
to click alink to activate it. Ofcourse this link is dependant on the
domain the site is hosted on.

Regards,
Stijn

On 10/3/07, Tarscher [email protected] wrote:

I need this for mail sending. I’m creating a user activation system
that wan run on multiple domains. When I send out a mail the user has
to click alink to activate it. Ofcourse this link is dependant on the
domain the site is hosted on.

Use url_for with :only_path set to false to generate full url’s

activate_link = url_for({:only_path => false}, :controller =>
‘account’, :action => ‘activate’, :id => @user)

Or, if you have a named route for activation, these generate full
url’s by default:

activate_link = activate_url(:id => @user)