Is there a way to detect user agent in Rails 3.1

22,927

Solution 1

Yep, just use this

request.env["HTTP_USER_AGENT"]
#or
request.user_agent

Solution 2

What about using a simple gem?

If I remember well, I used this one last time.

gem install user-agent

The same one on GitHub

I think that this is a good way to do it...

Share:
22,927
Daniël Zwijnenburg
Author by

Daniël Zwijnenburg

Freelance | Elixir | Ruby | Javascript | Devops

Updated on September 09, 2020

Comments

  • Daniël Zwijnenburg
    Daniël Zwijnenburg almost 4 years

    Possible Duplicate:
    Auto detect mobile browser (via user-agent?)
    Rails 3: HTTP_USER_AGENT

    Is there a way to detect the user agent from a current visitor? I'm currently working on a project to display video files. But for the ipad, iphone / samsung galaxy tab / internet explorer / firefox. I need to display video's is there a solid way to check which browser is visiting my rails app?

    Thanks guys!

  • Nicolas Guillaume
    Nicolas Guillaume over 12 years
    I'm not sure that we can call that a "solid way" :p
  • f0ster
    f0ster almost 11 years
    LOL there's a gem for that.
  • Franklin Yu
    Franklin Yu almost 8 years
    That's a quite old gem which does not even include Windows 8, and it has only one single release on RubyGems. I would suggest useragent with operating system support up to Windows 10.