简体   繁体   English

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

[英]Rails: Detecting user agent works in development but not production?

I am trying to detect Blackberry user agents in my app, which works fine in my development version. 我试图在我的应用程序中检测Blackberry用户代理,这在我的开发版本中工作正常。 But nothing happens when I redeploy the app in production. 但是,当我在生产中重新部署应用程序时,没有任何反应。

application_helper.rb application_helper.rb

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

application.html.erb 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. 我已经尝试使用rake tmp:cache清除缓存:清除并重启mongrel几次。 Apparently the HTTP_USER_AGENT is coming back nil in production. 显然,HTTP_USER_AGENT在生产中回归为零。 I am using Nginx with a mongrel cluster. 我正在使用Nginx和一个mongrel集群。

尝试:

request.user_agent

Are you using Apache or nginx in front of your mongrel(s)? 你在你的杂种前面使用Apache或nginx吗?

Are you logging the user_agent? 你是否记录了user_agent? This is from my nginx.conf: 这是我的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"';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Rails 6 中:视差在开发中有效但不在生产中 - In Rails 6: Parallax works in development but not in production Rails代码在开发中有效,但在生产中无效 - Rails code works in development but not in production Rails 5 CarrierWave Gem在生产中工作但不在开发中 - Rails 5 CarrierWave Gem Works in Production But Not In Development Rails 4-服务器在开发模式下工作,但不在生产模式下工作 - Rails 4 - server works in development mode, but not in production Rails 3:caches_page在开发中起作用,而不在生产中起作用 - Rails 3: caches_page works in development and not in production Rails Log Formatter在开发中可用,但不能在生产中使用 - Rails Log Formatter works in Development, but not Production Rails应用程序在开发中有效,但在生产中为空 - Rails application works in development but is empty in production Rails Ajax Spinner正在开发中,但未在生产中工作 - rails ajax spinner works in development but not production 方法在开发中有效,但在生产中不起作用Rails MongoDB - Method works in development but not production Rails MongoDB “添加新用户”在开发中有效,而不是在生产中 - 'Add New User' works in Development, not in Production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM