質問

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:

  1. I go to a page, say, google.com
  2. Then I type in: localhost:3000. Then has debugger on to catch request.env["HTTP_REFERER"]. But it yields nil

Is HTTP_REFERER only available when user comes to my site via a redirect, and not manually type it the address?

Thank you.

役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top