2014-04-13 50 views
8

我構建了一個站點。 在開發模式下,它很好地服務於.js文件。 然而,在生產模式下,會出現以下錯誤:Rails返回帶有MIME類型'text/html'的.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?

回答

8

我找到了答案。問題是/javascripts/items.jscontroller-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

+1

謝謝!完全相同的問題! –