respond_to block
June 5th, 2008
Don’t you just hate those gotchas out there that will consume some of too much of your time?
respond_to do |wants|
format.js
format.html
format.xml
end
This snippet will run fine on everything except IE browsers which will try to download the .js file. This is because IE doesn’t specify ‘text/html’ mime type explicitly in the HTTP ACCEPT header. So for it to work on IE .html needs to be defined first.
Firefox “text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/*;q=0.5”
on IE “image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, */“
To fix it the order just needs to be changed.
respond_to do |wants|
format.html
format.js
format.xml
end
Leave a Reply