Workaround for IE Overly Accepting in Rails’ respond_to format

19 Aug 2008 in Ruby on Rails, Troubleshooting by Garrick

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:


Comment | Trackback URL Short Link: http://grv.me/1521

Comments (3)

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.

MN Headhunter added these pithy words on Aug 19 08 at 1:22 am

I had not seen that yet. Good to know, thanks!

Phil Crissman added these pithy words on Sep 02 08 at 10:34 pm

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?”

Mr Frosti added these pithy words on Apr 09 09 at 4:45 pm

Add a Comment


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Related Entries




Creative Commons License
About Sitemap XHTML Sitemap XML
Wordpress theme is a heavily hacked version of "Modicus Remix" by Art Culture. Original by Upstart Blogger