Workaround for IE Overly Accepting in Rails’ respond_to format

Looks like Microsoft’s Internet Explorer will accept any format a web server is willing to give it.

This doesn’t play nicely with Rails’ 2.0+ respond_to feature. A slick little bit of code that asks the browser what it wants and replies accordingly.

Here’s a conversation between Rails & Firefox

Firefox: “Hey Rails, I want this url”
Rails: “No problem, which format would you like it in?”
Firefox: “HTML, please.”
Rails: “Here you go.”

Here’s the same conversation with Internet Explorer

IE: “Hey Rails, I want this url”
Rails: “No problem, which format would you like it in?”
IE: “Whatcha got?”
Rails: “I’ve got Atom, and…”
IE: (interputting) “OK THANKS!”
Rails: “…um, what? I wasn’t finished, really? ok, here you go.”

I had ordered my code alphabetically, so ‘atom‘ came before ‘html‘, like this:

respond_to do |format|
format.atom
format.html

end

Because IE is so, um, accepting, I’ve needed to put ‘html‘ first:

respond_to do |format|
format.html
format.atom

end

For more on this issue:

4 thoughts on “Workaround for IE Overly Accepting in Rails’ respond_to format

  1. MN Headhunter

    Garrick,

    Thank you for two things:

    -Swapping the email tonight at the late hour. I appreciate you taking the time to lend a hand.

    -For writing a post I can understand. I like to see hwo this stuff happens but rarely can I grasp it.

    Thanks.

    P.

  2. Mr Frosti

    The same thing just happened to me. Flipping the order above seems to resolve the issue, though I think there is something much lower in the stack going on here. Perhaps my IE is sending corrupted, or incompatible headers?

    Your conversation gave me a smile, though I think it would have gone more like:

    IE: “Hey Non-Microsoft Web Server, I want this url”
    Rails: “No problem, which format would you like it in?”
    IE: “Whats a format?”

Comments are closed.