Strange behaviour of respond_to in IE

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?

6 Responses to “Strange behaviour of respond_to in IE”

  1. 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. 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. 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. [...] I found a post on a similar problem here: Strange behaviour of respond_to in IE. [...]

  5. [...] 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. [...]

  6. [...] Strange behaviour of respond_to in IE - Ritu Kamthan Comment | Trackback URL Add a Comment [...]

Leave a Reply