Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

like image 596
kush Avatar asked Oct 24 '08 14:10

kush


2 Answers

Try:

request.user_agent
like image 184
Gabe Hollombe Avatar answered Oct 23 '22 20:10

Gabe Hollombe


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"';
like image 2
Mike Breen Avatar answered Oct 23 '22 21:10

Mike Breen