我正在尝试在我的应用程序中检测黑莓用户代理,这在我的开发版本中运行良好。但是当我在生产环境中重新部署该应用程序时,没有任何反应。
application_helper.rb
def blackberry_user_agent?
request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(Blackberry)/]
end
应用程序.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 与混合集群一起使用。
最佳答案
尝试:
request.user_agent
关于ruby-on-rails - rails : Detecting user agent works in development but not production?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/233802/