views:

3978

answers:

2

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/"&gt;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.

+1  A: 

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"';
Mike Breen
I am using nginx with a mongrel cluster.
dMix
can you post your nginx conf in a gist or a pastie?
Mike Breen
nginx conf: http://gist.github.com/19464
dMix
I tried adding that to line 21 of the conf and restarted the server. Still not working, any other ideas?
dMix
All that line done it set the format for the log. Did you check the nginx logs to see what it's reporting as the user agent for the blackberry?
Mike Breen
+7  A: 

Try:

request.user_agent
Gabe Hollombe
This is undocumented in APIdock, but it works.
Matthew Savage