Announcing:

LessMoney Conference will be June 7th in Tampa! Register today and make us smile super big!

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.

Learn how LessEverything built their consultancy to over $1,000,000 annual revenue at LessMoney Conference, June 7th in Tampa Florida. Each attendee will get early access to our upcoming ebook as well.

1 Comment

lanaer
lanaer said on February 05, 2007

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 :)

Leave a Comment

About Steven
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.

You Should...

Follow Steven on Twitter
Friend Steven on Facebook
Subscribe
LessEverything Copyright 2011 LessEverything.com
We don't like footers, they're kinda boring