Ruby-on-rails Rails 3 获取请求引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8071913/
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 02:19:48  来源:igfitidea点击:

Rails 3 get request referrer

ruby-on-railsruby-on-rails-3devise

提问by Johnny Klassy

I'm using Rails 3.0.9, Ruby 1.9.2, Devise 1.3.4 and has a need in Devise session new view to access the request url parameters although I see this as a general Rails request handling question. Essentially, a request is made to a Devise authenticated resource which redirects the user to the login screen. In the login view, I need access to the request url, eg, this is the request url called in the beginning

我正在使用 Rails 3.0.9、Ruby 1.9.2、Devise 1.3.4,并且需要在 Devise 会话新视图中访问请求 url 参数,尽管我认为这是一个通用的 Rails 请求处理问题。本质上,向 Devise 认证资源发出请求,该请求将用户重定向到登录屏幕。在登录视图中,我需要访问请求 url,例如,这是开头调用的请求 url

http://mysite.com/article/5?type=blah

In the redirect login page, I need access to that URL, anyone know how I can do this?

在重定向登录页面中,我需要访问该 URL,有人知道我该怎么做吗?

回答by topek

You can use request.refereror request.env['HTTP_REFERER']in your controller to get the referer url.

您可以在控制器中使用request.refererrequest.env['HTTP_REFERER']来获取引用网址。

回答by dRwg

I have just found out that WEBrick handles request.referrerincorrectly. But don't worry. Unicorn handles it right. I did't test that on other servers. You should check this with yours. I don't think that you use WEBrick as a production server.

我刚刚发现 WEBrick错误地处理request.referrer。不过别担心。独角兽处理得很好。我没有在其他服务器上测试过。你应该和你的一起检查一下。我不认为您将 WEBrick 用作生产服务器。