Here is a general pattern in my controller actions:
respond_to do |format| format.html {} format.js { render :layout => false } end
Ie, if the request is not AJAX, I will send the HTML content in the layout on the new page. If the request is AJAX, I would send the same content, but without the layout (so that it can be inserted into an existing page or placed in a lightbox or something else).
Therefore, I always return HTML to format.js , but Rails sets the Content-Type response header to text/javascript . This causes IE to throw this fun error message:
alt text http://dl.dropbox.com/u/2792776/screenshots/Screen%20shot%202010-02-25%20at%205.13.49%20PM.png
Of course, I could set the content type of the response every time I did this (or use after_filter or something else), but it looks like I'm trying to do something relatively standard, and I don't want to add additional template code.
How to fix this problem? Alternatively, if the only way to fix the problem is to change the type of response content, which is the best way to achieve the desired behavior (i.e. send content with layout for non-AJAX and the same content without layout for AJAX) without having to deal with by these mistakes?
Edit: There is more information in this blog post
content-type internet-explorer ajax ruby-on-rails
Tom lehman
source share