38

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!

Community
  • 1
  • 1
Daniël Zwijnenburg
  • 2,550
  • 2
  • 21
  • 28
  • 3
    Have you searched before asking this question? See [this question](http://stackoverflow.com/questions/5226946/rails-3-http-user-agent). – rdvdijk Oct 04 '11 at 16:10

3 Answers3

75

Yep, just use this

request.env["HTTP_USER_AGENT"]
#or
request.user_agent
Khaja Minhajuddin
  • 6,653
  • 7
  • 45
  • 47
CambridgeMike
  • 4,562
  • 1
  • 28
  • 37
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...

Nicolas Guillaume
  • 8,160
  • 6
  • 35
  • 44
  • 9
    LOL there's a gem for that. – f0ster Jul 30 '13 at 20:31
  • That's a quite old gem which [does not even include Windows 8](https://github.com/tj/user-agent/blob/1.0.0/lib/user-agent/agent.rb#L121), and it has only one single release on RubyGems. I would suggest `useragent` with operating system support up to [Windows 10](https://github.com/gshutler/useragent/blob/v0.16.7/lib/user_agent/operating_systems.rb#L6). – Franklin Yu Aug 28 '16 at 20:08
0

you can do it also client site with jquery ... there is a plugin

http://plugins.jquery.com/project/client-detect

server info
  • 1,335
  • 1
  • 14
  • 24