In recent days i have monitored a very strange behaviour of respond_to in IE.I am sharing my experience in hope that somebody might explain it to me. As i cudnt find anything related to this from my best teacher google
I am using edge rails in one of my projects. some where in that i have used respond_to in following way…
def show
respond_to |format| do
format.js {render :partial=>'show'}
format.html {}
end
end
When i checked the response in firefox for html and xml both requests type, it was perfect. But when i checked html response in IE 6 creates a blunder :O.It was returning a js file with the javascript response.
But when i changed the code and placed the html call first and then checked xml call it worked fine in IE too.
def show
respond_to |format| do
format.html {}
format.js {render :partial=>'show'}
end
end
Now can somebody tell me why is this happening and anyone else faced this issue ever?






December 22nd, 2006 at 4:59 am
One possible issue might be because of the ‘Accept’ header that the browser sends. The respond to checks the Accept header of the request object and then corresponds to execute the appropriate action. Firefos generally sends a Accept header which accepts text , html xml combinations , but IE sends something like ‘ */* ‘ . So when the request from IE comes , the first block is rendered beause it fits. Hence which ever is put first is being rendered.
Hope this helps.
–
Procrastinx
December 22nd, 2006 at 6:53 am
hmmm right thats what we have figured out lately.
But isn’t it one more addition in the long list of bugs in IE?? or is it a problem with respond_to? 8-|
December 23rd, 2006 at 6:38 am
Well im not that good at rails to comment if its a problem with respond_to. But considering that it works with other browsers , we can consider it to be a IE bug. One possible solution is to have a :before_filter ‘set_proper_accept_header’ in the controller and in the filter method do a request.env["HTTP_ACCEPT"] = “application/xml” if the user agent is IE.
Hope this helps.
_
Procrastinx
August 6th, 2007 at 12:18 pm
[...] I found a post on a similar problem here: Strange behaviour of respond_to in IE. [...]
October 12th, 2007 at 1:09 am
[...] It doesn’t, IE just tells the server “whatever you can send, I’ll take it”! Rails looks at it and says “alright, I’ll just give you the first one”. So you are forced to order items in the respond_to block with the topmost one being the one you usually want to send. This is really gross and hack-y and totally better explained elsewhere. [...]
August 19th, 2008 at 6:08 am
[...] Strange behaviour of respond_to in IE – Ritu Kamthan Comment | Trackback URL Add a Comment [...]
May 21st, 2009 at 9:26 pm
Thanks – this really helped me out.
February 5th, 2010 at 3:28 am
[...] for html and vice-versa. It worked fine in other browsers but just not IE. It seems a few other people were having this issue long ago but I could not find any recent info or a complete solution. I [...]
April 27th, 2010 at 6:51 am
I am amazed to see after so many years the thing hasn’t been resolved in respond_to , considering IE is the most widely used browser. Its the latest on the same issue http://www.chrissearle.org/node/565.
April 24th, 2013 at 1:23 am
Wonderful items from you, man. I have take note your stuff prior to and you’re simply extremely great. I really like what you’ve received here, really like what you are stating and the best
way during which you assert it. You make it entertaining
and you still care for to keep it sensible. I cant wait to learn
much more from you. That is actually a great site.