Rails:检测用户代理是否在开发中工作但不在生产中?

时间:2008-10-24 14:36:54

标签: ruby-on-rails ruby

我正在尝试在我的应用中检测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清除缓存:清除并重新启动mongrel几次。显然,HTTP_USER_AGENT在生产中回归为零。我正在使用Nginx和一个杂种群。

2 个答案:

答案 0 :(得分:44)

尝试:

request.user_agent

答案 1 :(得分:2)

你是否在你的杂种前面使用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"';