# About Browser detection

**URL:** <https://www.ruby-forum.com/t/about-browser-detection/154102>\
**Category:** Rails\
**Created:** [November 25, 2008, 1:07pm UTC](https://www.ruby-forum.com/t/about-browser-detection/154102 "2008-11-25T13:07:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saurav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@saurav](https://www.ruby-forum.com/u/saurav)\
**Post date:** [November 25, 2008, 1:07pm UTC](https://www.ruby-forum.com/t/about-browser-detection/154102/1 "2008-11-25T13:07:06Z")

</div>

Hi all ,  
I am new for ROR . Is there any way to detect the browsers  
from rails application??  
I having some issue of designing due to that, my tabs create gap,  
which is not there.???  
Any Idea?

---

<div class="post-metadata">

**Author:** ![saurav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@saurav](https://www.ruby-forum.com/u/saurav)\
**Post date:** [November 25, 2008, 1:18pm UTC](https://www.ruby-forum.com/t/about-browser-detection/154102/2 "2008-11-25T13:18:50Z")

</div>

Hi, yes, there are ways to detect the browser. You should also  
consider starting off with a professionally designed web site and just  
modify the contents. Unless you intend to tackle learning Rails and  
styling around browser differences (which have entire books written  
just for this).

Check out Open Source Web D.s for free templates to jump start  
your site.

[http://www.oswd.org/](http://www.oswd.org/)

–  
James M.

---

<div class="post-metadata">

**Author:** ![saurav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@saurav](https://www.ruby-forum.com/u/saurav)\
**Post date:** [November 26, 2008, 1:41am UTC](https://www.ruby-forum.com/t/about-browser-detection/154102/3 "2008-11-26T01:41:58Z")

</div>

On Nov 25, 2008, at 3:42 AM, saurav wrote:

> Hi all ,  
> I am new for ROR . Is there any way to detect the browsers  
> from rails application??  
> I having some issue of designing due to that, my tabs create gap,  
> which is not there.???  
> Any Idea?

Yes. Look in request.user\_agent.

So you might do something like this:

def ua\_identifier(ua\_string)  
return :chrome if ua\_string =~ /Chrome/i  
return :ie if ua\_string =~ /MSIE/  
return :safari if ua\_string =~ /Safari/  
return :firefox if ua\_string =~ /Firefox/i  
end

and then

do\_safari\_stuff if ua\_identifier(request.user\_agent) == :safari

The code I showed only figures out what generic kind of browser you  
are receiving a request from.

Hope this helps.
