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!

1
  • 3
    Have you searched before asking this question? See this question. Commented Oct 4, 2011 at 16:10

3 Answers 3

75

Yep, just use this

request.env["HTTP_USER_AGENT"] #or request.user_agent 
Sign up to request clarification or add additional context in comments.

1 Comment

I'm not sure that we can call that a "solid way" :p
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...

2 Comments

LOL there's a gem for that.
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.
0

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.