Ruby-on-rails 如何获取请求引用路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5819721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 01:01:23  来源:igfitidea点击:

How to get request referer path?

ruby-on-railsruby

提问by rails101

I need the path of the referrer. I don't want the domain name. For example, if the referrer is http://www.google.com/adsenseI want /adsense.

我需要推荐人的路径。我不要域名。例如,如果推荐人是 http://www.google.com/adsenseI want /adsense

回答by chadoh

request.refererreturns a string, but you can use Ruby's URI Moduleto wrap it and then simply ask it for its path:

request.referer返回一个字符串,但您可以使用Ruby 的 URI 模块来包装它,然后简单地询问它的路径:

if URI(request.referer).path == '/adsense'

回答by Adrian Serafin

You can access referer with

您可以访问引用

request.referer