Forum: Ruby on Rails what's the best way to detect browser?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
997433f165140d58f52b8c0d1d005dc1?d=identicon&s=25 Patrick Aljord (Guest)
on 2007-02-13 01:22
(Received via mailing list)
Hey all,
I'm looking for the best way to detect browser, especially I'm looking
to distinguish browsers as three different groups:
ie6 and older, netscape4 and older browsers
khtml/webkit/gecko/opera browsers

any idea?

thanx in advance

8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-02-13 04:43
(Received via mailing list)
Don't know if it's the best way, but you can get the User-Agent in the
controller with request.env['HTTP_USER_AGENT'].

Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2007-02-13 18:35
(Received via mailing list)
Will this work?

case request.user_agent
when /(gecko|opera|konqueror|khtml|webkit)/i
   return :gecko
when /msie\s+7\.\d+/i
   return :ie7
   return :older_browser
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2007-02-13 21:24
Check out for a nice piece of
Javascript code to detect on the client side.
15c80c9bf8be5ba6e5eeac9cb0304464?d=identicon&s=25 Ed Hickey (Guest)
on 2007-02-13 23:46
(Received via mailing list)
This topic is locked and can not be replied to.