views:

35

answers:

1

If i enter a url directly into the address bar of the browser, i get the following results:

logger.debug ENV['HTTP_REFERER'] // => 
logger.debug request.referrer    // => /

So the first one gives me a blank result which is what I expected but the second gives me the root? Is this correct? It seems from the docs (http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html#M000478) that they should return the same thing. And secondly, why does it return the root, if there was no referrer.

A: 

It returns the root correctly, as when you "hit" the app, you hit the root first (where routes.rb is), and then get redirected.

I would say request.referrer would be nice if used internaly on your application, to know wher (in the application) the user came from.

Whereas ENV['HTTP_REFERER'] works from a browser perspective, and will give you where the user came from before visiting your page.

Hope this helps you, and is clear enough.

Marcos Placona
That would make sense except that it looks like form the documentation that request.referrer is just grabbing ENV['HTTP_REFERER'] so they should be the same. Or am I reading that wrong?
kidbrax
Except that you're using the request scope, which deals with that request only.
Marcos Placona
ulitmately, what I am trying to do is find out if a user came from another website or from a page within our domain or subdomain. It appears that using request.referrer would not work for that then since it will always show the root if they came from outside.
kidbrax