(Ruby on Rails)页面标题以text / javascript的形式出现,当它不应该时 [英] (Ruby on Rails) Page header going as text/javascript, when it is not supposed to

查看:89
本文介绍了(Ruby on Rails)页面标题以text / javascript的形式出现,当它不应该时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Rails应用程序,但是在使用Internet Explorer访问它时发现了一个问题。
Firefox和Safari可以显示页面。
通过使用Internet Explorer时,在某些页面中它会尝试下载页面,而不是显示它。
我不知道会发生什么。

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.

这是我的application.html.erb的html标题:

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">
<html xmlns="http://www.w3.org/1999/xhtml">
<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"></script>

</head>

但我认为它与application.html.erb无关,因为有些页面显示正常和其他页面由ie下载。

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?

提前谢谢

UPDATE

我现在知道这与标题有关,它发送为mime内容类型text / javascript而不是text / html。
但我不知道为什么。
这是控制器代码,以防有人可以指出我的错误。

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显示Content-Type text / html; firefox上的charset = utf-8,Fiddler显示Content-Type text / javascript; Internet Explorer上的charset = utf-8。

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.

推荐答案

我总是把format.html放在第一位。这样,当IE发送一个奇怪的接受标头,比如' / '时,它将呈现它击中的第一个。在你的情况下,IE说它正在寻找任何东西,所以你发送它js。首先放置你的format.html块,你将是金色的。

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.

(参见我的答案在这里了解更多细节)

这篇关于(Ruby on Rails)页面标题以text / javascript的形式出现,当它不应该时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆