Safari bug with respond_to
written by Steven on February 05, 2007
Here is the bug I encountered: when I clicked on a link in Safari, rather than displaying the html, it acted like the page was an rss feed and tried to render it. While sorting this out I discovered that Safari is sending the header HTTP ACCEPT = "*/*". What this means is that it will accept anything the server gives it. Which on the surface seems just fine, but rails does not work that way. If the request (from the browser) does not specify a mime type in the url (http://..../controller.mime_type;action), then rails tries to figure out what the browser wants based on the accepts header. In this case the browser will take anything, so rails gave it the first thing on the list:
def action ..... respond_to do |wants| wants.rss {...} wants.atom {...} wants.html {...} end end
So rails returned rss and the whole thing was buggered. To fix the problem all I had to do was reorder the list so that wants.html {...} was first. Now Safari gets html by default, and get rss or atom when the correct link is clicked.
Leave a Comment

Steven Bristol has written code for the past 20 years. He like green vegetables and kittens, oh and butterflies too. He loves to throw ninja stars at his enemies.

1 Comment
I dunno that I’d call this a Safari bug; it seems to be more of an oddity of Safari that can result in a bug with Rails sites using respond_to that don’t have wants.html first ;)
Ok, enough with being a pedant. Thanks for the info :)