Sometimes it happens that our application doesn't support a browser with an older version, in that case, we wish to restrict a user from running our application on an older version. In rails, we have a solution to for this problem. Browsernizer is the gem that restricts an application to be open on old versions of the browser, and if a user tries to open the application on an older version, it will send a notification to the user to upgrade browser's version.
Lets install it, by adding following line to your Gemfile and run bundle install:
Once the gem is installed, link it with:
rails generate browsernizer:install
After this open a file config/initializers/browsernizer.rb created by browsernizer.It will look something like this:
This Initializer file is specifying that this our application will support IE8+, FF4+, Opera 11.1+ and Chrome 7+. The browsers that are not supported by the application can be redirected to any page that you specify in config.location option in initializer file. In our case it will be redirected to the upgrade_browser.html page, that could be a dynamic or static file.
In some cases we need to completely block some browsers from accessing our application. In such cases we need to set browser to false.
Let say we need to block Firefox browser:
config.supported "Firefox", false
Another way of restricting browsers is by accessing browsernizer information from request.env['browsernizer'] in the controller.
For example set a before filter to display notification:
flash.notice = "Please upgrade your browser"