How to detect browser type and its version

Syed Raza picture Syed Raza · Apr 26, 2011 · Viewed 35.4k times · Source

how can i detect browser type and its version in Rails. I want to put check on the version of specific browser and if its not required browser version than ask user to upgrade it.. i use below specified command but as its not following a standard pattern am unable to use it.

request.env['HTTP_USER_AGENT'] 

Chrome out put is below
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.205 Safari/534.16
Safari out put is below
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1
FireFox out put is below
Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0
Opera out put is below
Opera/9.80 (Windows NT 5.1; U; en) Presto/2.8.131 Version/11.10
Internet Explorer out put is below
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)

Answer

Nishutosh Sharma picture Nishutosh Sharma · Dec 11, 2012

Try the browser gem. Very simple and can solve your purpose.

You can find the gem Here very easy to use.