Reputation: 20415
I would like to save the url that user visited right before landing to my site. How should I do it in Rails?
I tried
request.env["HTTP_REFERER"]
but couldn't retrieve the previous url.
May be this is a wrong way to test it, but here is what I did:
Is HTTP_REFERER only available when user comes to my site via a redirect, and not manually type it the address?
Thank you.
Upvotes: 1
Views: 505
Reputation: 17323
You can't see the last page the user was on if you type a new URL in. HTTP_REFERER
is only set when you click on a link. It'd be a pretty big privacy invasion if you could see whatever arbitrary URL the user was previously viewing.
Upvotes: 2
Reputation: 91
This is sent in the HTTP headers as "referer". So, request.referer should have what you need if the user's browser and/or any proxies are not filtering it out.
Upvotes: 1