How can I detect the user's browser in Rails? Thanks.
on 2006-02-08 00:50
on 2006-02-08 01:02
on 2006-02-08 13:43
On Tuesday 07 Feb 2006 23:01, Kent S. wrote: > request.user_agent Though please use that with extreme care and discretion, Thiago - browser sniffing based on user-agent string is generally a very bad idea. I'm not saying you're *definitely* doing it the wrong way (since I don't know what you're trying to do), but chances are there's a better way you can solve almost any scenario where user-agent detection used to be the accepted solution a few years back. Server-side user-agent sniffing in particular... if you're using that to serve up different versions of pages to different browsers, please seriously reconsider! The only thing I would use server side UA detection for these days is something like error log generation for the site owner. Public-facing server-side UA detection is a big no-no, as far as I'm concerned - it doesn't work, unnecessarily hurts users, isn't future proof, and basically isn't even particularly necessary in the first place. If you code to web standards, there are a lot of easy methods you can use to make your site gracefully degrade for non-standards compliant (eg. older... or Microsoft written, hehehe!) browsers. I don't want to go into too much detail here, because I hope you already know most of these techniques. If not, a good place to start is... http://www.zeldman.com/dwws/ ... which is one of the best web development books I ever bought. All I wanted to say is that whenever anyone mentions browser detection, especially server side, my alarm bells go off!! So I hope you are using it for the right reasons, and if so, please accept my apologies for the unwarranted concern! Cheers, ~Dave -- Dave S. Rent-A-Monkey Website Development http://www.rentamonkey.com/ PGP Key: http://www.rentamonkey.com/pgpkey.asc