Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

simplify user-agent detection in Rails

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 doc
Octocat-spinner-32 lib
Octocat-spinner-32 tests
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 user_agent_info.gemspec



Mehmet Celik (mehmet at

simplify user-agent detection in Rails


Hosted on Gemcutter

gem install user_agent_info Your Rails app add next line to config/environment.rb config.gem “user_agent_info”


It extends ActionController::Request and parses the requests HTTP_USER_AGENT header so it can be queried. The supported browsers are IE, Firefox, Chrome, Opera


class UpgradeBrowserController < ApplicationController

		def index
  			@upgrade = request.user_agent_info.isIE_or_worse?('6.0')   


More Examples

Depending on your browser you could get output like this request.user_agent_info['header'] ==> Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv: Gecko/20091016 Firefox/3.5.4 request.user_agent_info['platform'] ==> Macintosh request.user_agent_info['name'] ==> Firefox request.user_agent_info['name_display'] ==> Mozilla Firefox request.user_agent_info['cpuos'] ==> Intel Mac OS X 10.5 request.user_agent_info['language'] ==> en-US request.user_agent_info['version'] ==> 3.5 request.user_agent_info['engine'] ==> Gecko/20091016

Query for specific browsers request.user_agent_info.isIE? ==> true if browser is Internet Explorer request.user_agent_info.isFirefox? ==> true if browser is Mozilla Firefox request.user_agent_info.isChrome? ==> true if browser is Google Chrome request.user_agent_info.isOpera? ==> true if browser is Opera

You can also query if it is better or worse then a certain browser version. The example below uses IE but you can replace it by Firefox, Chrome or Opera request.user_agent_info.isIE?('6.0') ==> true if browser is Internet Explorer version 6.0 '==' request.user_agent_info.isIE_or_worse?('6.0') ==> true if browser is Internet Explorer version worse or equal to 6.0 '<=' request.user_agent_info.isIE_and_worse?('6.0') ==> true if browser is Internet Explorer version worse then 6.0 '<' request.user_agent_info.isIE_or_better?('6.0') ==> true if browser is Internet Explorer version better or equal to 6.0 '>=' request.user_agent_info.isIE_and_better?('6.0') ==> true if browser is Internet Explorer version better then 6.0 '>'

Something went wrong with that request. Please try again.