Rails:检测用户代理在开发中有效但在生产中无效? [英] Rails: Detecting user agent works in development but not production?

查看:40
本文介绍了Rails:检测用户代理在开发中有效但在生产中无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中检测 Blackberry 用户代理,这在我的开发版本中运行良好.但是当我在生产环境中重新部署应用时没有任何反应.

application_helper.rb

 def blackberry_user_agent?request.env["HTTP_USER_AGENT"] &&request.env["HTTP_USER_AGENT"][/(Blackberry)/]结尾

application.html.erb

<% if blackberry_user_agent?-%><div class="message"><p>使用黑莓?<a href="http://mobile.site.ca/">使用移动优化版本</a>.</p>

我尝试使用 rake tmp:cache:clear 清除缓存并重新启动了 mongrel 几次.显然 HTTP_USER_AGENT 在生产中恢复为零.我将 Nginx 与 mongrel 集群一起使用.

解决方案

你是在你的杂种面前使用 Apache 还是 nginx?

您是否在登录 user_agent?这是来自我的 nginx.conf:

log_format main '$remote_addr - $remote_user [$time_local] $request ''"$status" $body_bytes_sent "$http_referer" ''"$http_user_agent" "http_x_forwarded_for"';

I am trying to detect Blackberry user agents in my app, which works fine in my development version. But nothing happens when I redeploy the app in production.

application_helper.rb

  def blackberry_user_agent?
    request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(Blackberry)/]
  end

application.html.erb

<% if blackberry_user_agent? -%>
<div class="message">
<p>Using a Blackberry? <a href="http://mobile.site.ca/">Use the mobile optimized version</a>.</p>
</div>

I've tried clearing the cache using rake tmp:cache:clear and restarted mongrel a few times. Apparently the HTTP_USER_AGENT is coming back nil in production. I am using Nginx with a mongrel cluster.

解决方案

Are you using Apache or nginx in front of your mongrel(s)?

Are you logging the user_agent? This is from my nginx.conf:

log_format main '$remote_addr - $remote_user [$time_local] $request '
                  '"$status" $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "http_x_forwarded_for"';

这篇关于Rails:检测用户代理在开发中有效但在生产中无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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