Mobile_Fu, Internet Explorer and respond_to

Today I noticed that List Kung Fu displays the mobile version of the list page when I browse there with regular desktop Internet Explorer. Surfing to the same page with Firefox or Opera on the same machine worked fine and just returned the regular HTML page.

So what’s up?

Simple… Internet Explorer sends a really funny accepts header, none of the formats actually is text/html. Thus HTML is covered with an implicit */*. That’s not awesome (in good IE manner), but not really a problem. A problem it just becomes with something like this in your controller action:

      respond_to do |format|
        format.mobile
        format.html
      end

Since Internet Explorer doesn’t send an explicit accept for text/html, Rails would just default to the first format, in above case format.mobile and then correctly return the mobile version of the view. The fix is easy. Just move format.html to the first position:

      respond_to do |format|
        format.html
        format.mobile
      end

Now */* would default to format.html.

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
This entry was posted in RubyOnRails. Bookmark the permalink.

One Response to Mobile_Fu, Internet Explorer and respond_to

  1. lukas2 says:


    Thanks for posting this. I’ve solved my related issue by setting a before_filter like this:


    def set_default_response_format
    request.format = :html if params[:format].nil?
    end

    IE8 requests are now processed correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">