Ruby on Rails - request.env['HTTP_REFERER'] 返回 nil [英] Ruby on Rails - request.env['HTTP_REFERER'] returns nil

查看:36
本文介绍了Ruby on Rails - request.env['HTTP_REFERER'] 返回 nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存 http_referer,以便在用户登录后将其发送回该 url.现在我的控制器中有一个 before_filter,如果没有创建会话,它会将它们发送到登录页面通过redirect_to.但是,当我检查 HTTP_REFERER 时,它为零(而REQUEST_URI"确实返回了我最初来自的位置).

I am trying to save the http_referer so I can send the user back to that url after he has logged in. Right now I have a before_filter in my controllers that sends them to a log in page if a session has not been created via a redirect_to. However when I check the HTTP_REFERER it is nil (whereas 'REQUEST_URI' does return where Im originally coming from).

谢谢.

推荐答案

HTTP_REFERER 是浏览器在请求中设置的 HTTP 标头,其中包含前一个网页的地址,从该网页链接到当前请求的页面.直接导航到页面时不会设置.

HTTP_REFERER is an HTTP header set by the browser in the request containing the the address of the previous web page from which a link to the currently requested page was followed. It will not be set when directly navigating to a page.

REQUEST_URI(也可通过 request.request_uri()) 是用于访问 Rails 控制器/操作的统一资源标识符,应该始终设置.

REQUEST_URI (also available via request.request_uri())is the Uniform Resource Identifier used to access the Rails controller/action and should always be set.

将此调试代码放入您的视图中:

Throw this debugging code into your view:

<ul>
<% request.env.each do |item| %>
    <li><%= item[0] %> : <%= item[1] %></li>
<% end %>
</ul>

如果未设置 HTTP_REFERER,请确保您通过链接或重定向导航到该页面,然后查看是否已设置.

If HTTP_REFERER is not set, make sure you are navigating to that page via a link or redirect and see if it is set then.

您的浏览器也有可能未设置 HTTP_REFERER 标头.确保您没有影响此的附加组件.您可以使用名为 Tamper Data 的漂亮 Firefox 附加组件来查看正在发送的标头.

There is also a chance your browser is not setting the HTTP_REFERER header. Be sure you do not have an add-on affecting this. You can use a nifty Firefox add-on called Tamper Data to see the headers being sent.

这篇关于Ruby on Rails - request.env['HTTP_REFERER'] 返回 nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆