开发者

In rails whats the best way to get the site that a user came from? I am getting conflicting info

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜