views:

23

answers:

2

Hi,

Is there any really easy way to get to know, what browser has called controller's action.

I would like to have a code for my controller, like this:

if mighty_lib.browser.name == "Safari"
   if mighty_lib.browser.version >= 5
       # Glad to see you, Safari 5, there is a stunning, interactive page for you.
   elsif mighty_lib.browser.version >= 4
       # Glad to see you, Safari 4, there is a less advanced page for you.
   end
if mighty_lib.browser.name == "Firefox"
   # Quick brown fox jumps over the lazy dog
elsif mighty_lib.browser.name == "IE"
   # Oh, my god ... Change your browser ! There is a "Jurassic Park" movie for you
end
A: 

You may use this old plugin, or write some raw code that uses request.env["HTTP_USER_AGENT"]. Also, take a look at this comment at Ruby forums.

floatless
+2  A: 

I would suggest that the server is not the best place to handle different browser requirements - it is generally a much better approach to use smart css and (unobtrusive) javascript to turn features on and off on the client-side according to the specific capabilities of the client as opposed to fixing on specific versions.

Toby Hede