Home > General, Ruby on Rails, rails > Strange behaviour of respond_to in IE

Strange behaviour of respond_to in IE

December 10, 2006 Ritu Leave a comment Go to comments

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?

Categories: General, Ruby on Rails, rails
  1. Procrastinx
    December 22, 2006 at 4:59 am | #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. December 22, 2006 at 6:53 am | #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. Procrastinx
    December 23, 2006 at 6:38 am | #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. May 21, 2009 at 9:26 pm | #4

    Thanks – this really helped me out.

  1. August 6, 2007 at 12:18 pm | #1
  2. October 12, 2007 at 1:09 am | #2
  3. August 19, 2008 at 6:08 am | #3