How do you get the base url of the HTTP request?

Hi,

How do you get the base url of the HTTP request in the controller?

For example, if my app is hosted on http://fudge.wow.com/

and I make a request to http://fudge.wow.com/users/1

How do I get the http://fudge.wow.com/ part of the request in the show
action of the users_controller?

Thank you!

David :slight_smile:

*request.env[‘HTTP_HOST’]
*will give you => fudge.wow.com
*
request.env[SERVER_PROTOCOL]
*will give you server protocol i.e. *=> HTTP

*For more details refer to :
http://wiki.rubyonrails.org/rails/pages/VariablesInRequestEnv
*
*
*
*
On Sun, Apr 27, 2008 at 9:59 PM, David B.
[email protected]
wrote:

action of the users_controller?

Thank you!

David :slight_smile:


Arpit J.
Senior Undergraduate Student
Department of Computer Science & Engineering
Indian Institute of Technology, Kharagpur, India.
Ph. : +919733567185
Alt. email: arpit AT intinno.com
Web: http://www.arpitjain.com

All that information is in “request”

I’m not 100% sure, but I think what you want is request.path or
request.url

If you do try:
raise request.inspect

It will tell you everything thats inside request.

Hope this helps,
Luke

David B. wrote:

Hi,

How do you get the base url of the HTTP request in the controller?

For example, if my app is hosted on http://fudge.wow.com/

and I make a request to http://fudge.wow.com/users/1

How do I get the http://fudge.wow.com/ part of the request in the show
action of the users_controller?

Thank you!

David :slight_smile:

Thanks a lot. I’ll give it a try.
D :slight_smile:

Luke G. wrote:

All that information is in “request”

I’m not 100% sure, but I think what you want is request.path or
request.url

Also try request.relative_url_root. But use with caution, because all
the URIs
inside your application should be subject to routes.rb. You should
expect to
change that, and everything will work with the new routes.

If you do try:
raise request.inspect

It will tell you everything thats inside request.

Sometimes .inspect is so obliging, and sometimes not! For a different
view, use
raise public_methods.sort.inspect


Phlip

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