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. => HTTPFor more details refer to :

http://wiki.rubyonrails.org/rails/pages/VariablesInRequestEnv

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 Beckwith wrote:

Luke Grimstrup 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

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