views:

270

answers:

2

Im developing an Rails application, but I found a problem when accessing it with internet explorer. Firefox and Safari displays the pages all right. Althrough, when using internet explorer, in some pages it tries to download the page, instead of displaying it. I have no idea what could be happening.

Here is the html header of my application.html.erb:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head id="otzee_header_scripts">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test site</title>
<meta name="robots" content="index, follow" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="NZN - No Zebra Network" />
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
  <%= stylesheet_link_tag "default.css" %>
  <%= stylesheet_link_tag "#{site_theme}/default", :id => 'theme_change_css' %>
  <%= stylesheet_link_tag "#{site_theme}/toyart.css", :id => 'theme_change_bg_css' %>

<!-- Includes Globais -->
  <%= javascript_include_tag 'jquery' %>
  <%= javascript_include_tag 'jquery-ui' %>
  <%= javascript_include_tag 'jrails' %>
  <%= javascript_include_tag 'games' %>
  <%= javascript_include_tag 'users' %>
  <%= javascript_include_tag 'application' %>
  <%= stylesheet_link_tag 'application' %>
  <%= stylesheet_link_tag 'acts_as_taggable_stylesheet' %>

  <%= yield(:head) %>
<!-- Globais -->

<!--[if lte IE 6]>
<link href="stylesheets/ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script src="http://www.google.com/jsapi"&gt;&lt;/script&gt;

</head>

But I dont think its related to the application.html.erb, since some pages display normal and other are downloaded by the ie.

Do have any clue about what could be causing this? or how to solve it?

Thank you in advance

UPDATE

I know now that is related to the headers, its sending as mime content-type text/javascript instead of text/html. But i dont know why. Here is the controller code, in case someone can point my mistake, please.

def index
    respond_to do |format|
      format.js do
        if params[:bookmarks] != 0
          @games_infos  = current_user.games_info_bookmarks params[:page], 8
          @bookmarks    = 1
        else
          @games_infos  = current_user.games_info_collection params[:page], false, 8
          @bookmarks    = 0
        end       
      end      
      format.html do
        @invites = current_user.friends_pending
        @whats_new = WhatsNew.find_user_network_updates @me, 1, 13
        @games_infos  = @me.games_info_bookmarks params[:page], 8
        @bookmarks    = @games_infos.size
        @games_infos  = @me.games_info_collection(params[:page], false, 8) unless @bookmarks > 0
        @friends      = @me.friends_on_off
        @high_scores  = @me.high_scores
      end
    end
  end

Obs: firebug shows Content-Type text/html; charset=utf-8 on firefox, and Fiddler shows Content-Type text/javascript; charset=utf-8 on the internet explorer.

+3  A: 

Your pages probably have the wrong MIME type.

Look at the response in Fiddler and check the MIME type.

To work correctly in IE, you should probably use a MIME type of text/html.

SLaks
Yes you are right, its sending the mime as text/javascript, but I have no idea why.the page has its respond_to for both format.js and format.html
Tiago
What webserver are you using? It may have a setting that is overriding your script.
jeffamaphone
It's running on mongrel. But firefox seems to get the correct header, while ie get this text/javascript.I tryed to force the header in the controller to be text/html, but still the same.
Tiago
True, but this is not the root cause. IE is basically saying- give me anything, so Rails sends the first thing that matches. See my answer for more.
MattMcKnight
+2  A: 

I always put the format.html first. That way when IE sends a weird accepts header, like '/', it will render the first one it hits. In your case, IE said it's looking for anything, so you're sending it js. Put your format.html block first and you will be golden.

(See my answer here for some more details)

MattMcKnight
that did the trick, thank you
Tiago