ruby-on-rails – Rails返回MIME类型为“text / html”的.js
发布时间:2020-12-17 04:38:01 所属栏目:百科 来源:网络整理
导读:我建立了一个网站. 在开发模式下,它很好地服务于.js文件. 但是,在生产模式下,会发生以下错误: Refused to execute script from 'http://bowuzhi.herokuapp.com/javascripts/items.js' because its MIME type ('text/html') is not executable,and strict MI
我建立了一个网站.
在开发模式下,它很好地服务于.js文件. 但是,在生产模式下,会发生以下错误: Refused to execute script from 'http://bowuzhi.herokuapp.com/javascripts/items.js' because its MIME type ('text/html') is not executable,and strict MIME type checking is enabled. 而http://bowuzhi.herokuapp.com/javascripts/items.js的内容是html: <div class='page-header'> <a class="btn btn-primary" href="/zh-TW/items/new"><span class='glyphicon glyphicon-plus'></span> New </a><h1>Catalog</h1> </div> <div class='row' id='items'> </div> <div class='row'> <div class='col-md-12'> </div> </div> <script src="/javascripts/items.js"></script> 这个网站是在heroku:http://bowuzhi.herokuapp.com. 为什么.js原来是html? 解决方法
我找到了答案.问题是/javascripts/items.js是
controller-specified asset.它是通过在视图上使用javascript_include_tag帮助程序而不是包含在清单文件(application.js)中包含的,因此它不会被预编译.
为了解决这个问题,我将config.assets.precompile =%w(items.js)行添加到我的config / application.rb中. 您可以在此问题中找到更多信息:rails-3-1-asset-pipeline-how-to-load-controller-specific-scripts. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |