Forum: Ruby on Rails Browser Detection

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Thiago J. (Guest)
on 2006-02-08 00:50
(Received via mailing list)
How can I detect the user's browser in Rails?

Thanks.
Kent S. (Guest)
on 2006-02-08 01:02
(Received via mailing list)
request.user_agent

Kent.
Dave S. (Guest)
on 2006-02-08 13:43
(Received via mailing list)
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
This topic is locked and can not be replied to.