【问题标题】:Rails javascript_include_tag: 'type="text/javascript"' missingRails javascript_include_tag: 'type="text/javascript"' 缺失
【发布时间】:2013-11-02 11:58:02
【问题描述】:

当我在视图中使用 javascript_include_tag 时,我的 Ruby on Rails 4.0.0(Ruby 版本 1.9.3)实例没有将 type 属性添加到 <script> 标记。

我应该在 Rails 中调整什么来解决这个问题?

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-4


【解决方案1】:

正如其他人所提到的,type 属性不是必需的。

但是,如果您绝对需要定义它,可以通过将哈希作为javascript_include_tag 的最后一个参数传递给标签上的任意属性。

也就是说,

javascript_include_tag "test", :type => "text/javascript"

会产生

<script src="/javascripts/test.js" type="text/javascript"></script>

【讨论】:

    【解决方案2】:

    不应该。 <script> 标签不再需要 type 属性,它们被假定为 JavaScript。

    我应该在 Rails 中调整什么来解决这个问题?

    没什么,因为这不是问题。

    【讨论】:

    • 在 Google Chrome 控制台上:“localhost/:7 资源解释为脚本,但使用 MIME 类型 text/html 传输:“localhost:3000”。2015-01-24 08:08:31.293(index) :1 拒绝执行来自 'localhost:3000/javascripts/site.js' 的脚本,因为它的 MIME 类型 ('text/html') 不可执行,并且启用了严格的 MIME 类型检查。"
    • 我认为你是对的......输出真的是 html 而不是 javascript。我们不需要将 :type 添加到 javascript。
    猜你喜欢
    • 2014-06-15
    • 1970-01-01
    • 1970-01-01
    • 2012-10-16
    • 2016-12-12
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    相关资源
    最近更新 更多