Follow Along as I Stumble on the Path to Learning RoR

Internet Explorer is a Hideous Beast (but I still need to accommodate it)

I found out [rudely] what a hideous beast Internet Explorer is one day when opening my app in IE7.  I could hardly recognize my app – yes the text matched, but styles were changed, fonts didn’t work, colors were wrong, corners were right angles, buttons were too big….

While some things can be adjusted to match (or look similar) in Chrome, Firefox and Internet Explorer, there are things that will just not look (or work) the same, no matter how hard you try.  IE has just lagged so far behind the other browsers in terms of style.  I ended up having to create alternate versions of parts of my views depending on the browser.

Luckily for me, I found the browser gem which detects the browser the user is using for you.

As mentioned by Nando Vieira, who created the gem, you can then do things like:

<% if browser.ie6? %>
  <p>Your're running an older IE version. Please update it!</p>
<% end %>

For me, I had to implement it a little differently than the gem instructions say, to make it work.  Instead of:

require "rubygems"
require "browser"

I put this in the application_controller:

before_filter :current_browser def current_browser   @browser = Browser.new(:ua => request.user_agent) end

then I was able to use browser detection throughout my app.

Advertisements

Comments are closed.