【问题标题】:Rails: Detecting user agent works in development but not production?Rails:检测用户代理在开发中有效,但在生产中无效?
【发布时间】:2008-10-24 14:36:53
【问题描述】:

我正在尝试在我的应用中检测 Blackberry 用户代理,这在我的开发版本中运行良好。但是,当我在生产环境中重新部署应用程序时,什么也没有发生。

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>

我尝试使用 rake tmp:cache:clear 清除缓存并重新启动 mongrel 几次。显然 HTTP_USER_AGENT 在生产中归零。我正在将 Nginx 与杂种集群一起使用。

【问题讨论】:

    标签: ruby-on-rails ruby


    【解决方案1】:

    试试:

    request.user_agent
    

    【讨论】:

      【解决方案2】:

      你是在你的 mongrel(s) 前面使用 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"';
      

      【讨论】:

      • 我正在使用 nginx 和一个 mongrel 集群。
      • 你能把你的 nginx conf 发布在 gist 或 paste 中吗?
      • 我尝试将其添加到 conf 的第 21 行并重新启动服务器。还是不行,还有其他想法吗?
      • 所有这行都为日志设置了格式。您是否检查了 nginx 日志以查看它作为黑莓用户代理报告的内容?
      猜你喜欢
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 2015-03-24
      • 2013-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多