Tuesday, September 28, 2010

Rails respond_to and IE File Download Security Warning

As discussed in my earlier post, I am working on a WEB API integration project involving Radiant. This is a public facing website and requires full support of Internet Explorer. So far, IE has proved to be a great pain. I have got an IFRAME rendering pages from another web application. Now, this application had a controller code with respond_to block.

def method_name
#some RUBY code
respond_to do |format|
format.js {#render some JSON}
format.html {#redirect to somewhere}

Now, everything seemed to be working good on FireFox and Chrome. Next was the turn of IE. As expected, MORE PROBLEMS.....!! It didn't work!!! It started showing File Download Security Warning Dialog. I had no clue what it was doing. I was totally stumped. Finally, after a bit of googling I came across this post. It saved my day.

As mentioned in the post, I tried printing the request.format for normal HTML request. To my surprise, IE was registering the Mime::Type to be "image/gif". Also, format.html? was nil.

I tried accessing the same action from FireFox. This time, the request format was set correctly to be "text/html".

Now, there is no Mime::Type registered for "image/gif". Hence, first accept type was taking preference. The solution (moving format.html before format.js) mentioned in the post worked for me.