# Browser Detection

**URL:** <https://www.ruby-forum.com/t/browser-detection/102257>\
**Category:** Rails\
**Created:** [February 7, 2006, 11:50pm UTC](https://www.ruby-forum.com/t/browser-detection/102257 "2006-02-07T23:50:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiago\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@Thiago\_J](https://www.ruby-forum.com/u/Thiago_J)\
**Post date:** [February 7, 2006, 11:50pm UTC](https://www.ruby-forum.com/t/browser-detection/102257/1 "2006-02-07T23:50:23Z")

</div>

How can I detect the user’s browser in Rails?

Thanks.

---

<div class="post-metadata">

**Author:** ![Thiago\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@Thiago\_J](https://www.ruby-forum.com/u/Thiago_J)\
**Post date:** [February 8, 2006, 12:02am UTC](https://www.ruby-forum.com/t/browser-detection/102257/2 "2006-02-08T00:02:35Z")

</div>

request.user\_agent

Kent.

---

<div class="post-metadata">

**Author:** ![Thiago\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@Thiago\_J](https://www.ruby-forum.com/u/Thiago_J)\
**Post date:** [February 8, 2006, 12:43pm UTC](https://www.ruby-forum.com/t/browser-detection/102257/3 "2006-02-08T12:43:51Z")

</div>

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…

> **[Designing with Web Standards](https://en.wikipedia.org/wiki/Designing_with_Web_Standards)**
>
> Designing with Web Standards, first published in 2003 with revised editions in 2007 and 2009, is a web development book by Jeffrey Zeldman. The book’s audience is primarily web development professionals who aim to produce design work that complies with web standards. The work is used as a textbook in over 85 colleges.
> Written by Jeffrey Zeldman, a leading proponent of standards-compliant web design, Designing with Web Standards guides the reader on how to better utilize web standards pragmatical...

… 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

> **[Tree Removal Service For Home & Businesses in Salt Lake City, UT](https://www.rentamonkey.com/)**
>
> Rent A Monkey Tree Service provides the safest, highest-quality tree removal for Salt Lake City, UT homes and businesses. Request a service today!

PGP Key: [http://www.rentamonkey.com/pgpkey.asc](http://www.rentamonkey.com/pgpkey.asc)
