10 Dec 2006

Strange behaviour of respond_to in IE

General, rails, ruby on rails posted 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?

  • http://virtualfunction.net Jason Earl

    Ditto, I literally came across the same issue. I’d think it will be safe to blame IE. I wonder if the Rails team will be doing some browser sniffing to sort this as I’m sure it will annoy many others. I’m too lazy to look into the cause now (it’s 4:30am here), but if you dump the response/request controller instance varaibles to a log when using both IE and FF, you could probably see where the issue lies. Something like RAILS_DEFAULT_LOGGER

  • http://paulodeon/com Paul Odeon

    I’m seeing the same problem, and solved it with the same solution.

    It is because of the IE accepts header, this is the IE7 accepts type header

    image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-icq, application/x-shockwave-flash, */*

    The firefox accepts type header is:

    text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

    And the default prototype request header is

    text/javascript, text/html, application/xml, text/xml, */*

    This is mentioned in the comments on this post http://weblog.jamisbuck.org/2006/3/27/web-services-rails-style

blog comments powered by Disqus