Alex Wayne wrote:
A little further investigation, leads to some differences in the accept
header:
Firefox sends:
"HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
IE7 sends:
"HTTP_ACCEPT"=>"*/*"
Could this be the culprit? Perhaps I need to declare a default format
somewhere?
I think I figured this out. IE7 is a tricky bastard. Basically, it
sends different accept headers when clicking on links, and direct
address bar access, than it does when refreshing.
Firefox's accept header lists "text/html" first, and this tells rails to
trigger the "format.html" part of the respond to block.
IE7, on the other hand, sends an HTTP_ACCEPT header like so when you
click a link:
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/ag-plugin, */*"
So rails looks at my respond_to block, and looks at that header. it
looks for a gif responder, an x-bitmap responder, and then a jpg
responder, which I do have. Rails declares is a match and sends it out.
Normally people don't generate images via a respond_to block, which is
why this hasn't come up much. Sadly, my app does this, and its actually
a pretty clean solution.
So thing that made this such a nightmare to track down was when I
refreshed the HTTP_ACCEPT header turned into simply "*/*", allowed rails
to pick the default, which was html.
The solution is a gloabl before filter, that after some trial and error,
looks like this:
def set_default_format
bad_accept_header = "image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, application/x-shockwave-flash, application/ag-plugin, */*"
if request.headers['User-Agent'] =~ /MSIE/ &&
request.headers['HTTP_ACCEPT'] == bad_accept_header
request.format = Mime::Type.lookup_by_extension(:all)
end
end
This forces it to behave if that funky header gets shoved to rails.
Hope this helps someone.
Once again, IE has caused me hours of pain, when all other browsers
performed flawlessly. Grumble... humbug... grrr...