Solution 1:

The browser gem is specifically designed for browser detection in Rails.

Solution 2:

There's library ruby library over at GitHub: https://github.com/gshutler/useragent

I use it myself, and it's working as advertised so far. For your use case, you could probably call the library from within a helper method in your Rails project or something similar.

That said, I'm not completely sure if the HTTP_USER_AGENT is exposed to Rails helper methods. In case it isn't exposed, you could always expose a controller method as a helper (by using AbstractController::Helpers::ClassMethods#helper_method).

Solution 3:

Try request.env['HTTP_USER_AGENT'], this will return your client's User Agent. There's also a quick helper posted by Hubert Łępicki