Strange behaviour of respond_to in IE

2006 December 10
by Ritu

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?

7 Responses leave one →
  1. 2006 December 22
    Procrastinx permalink

    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

  2. 2006 December 22

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

  3. 2006 December 23
    Procrastinx permalink

    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

  4. 2009 May 21

    Thanks – this really helped me out.

Trackbacks & Pingbacks

  1. Rails’ respond_to method | info.michael-simons.eu
  2. Wejoinin Blog » Blog Archive » RSS feeds gone haywire!
  3. Workaround for IE Overly Accepting in Rails’ respond_to format -- Garrick Van Buren .com

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS