문제

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