2014-03-19 45 views
1

當我的Ruby on Rails項目處於部署模式時,無法運行任何JavaScript。我在vendor/assets/javascript/theme/index-slider.js有一個js。它有一個警報在此文件來測試JavaScript的工作:Javascript無法在Ruby on Rails中部署模式

alert('TestTestTest'); 

當我運行在開發模式下的項目,所有的JavaScript運行正常。另外,如果我將<script>alert("Testme");</script>添加到我的index.html.erb文件中,則該JavaScript以生產模式運行。

進行更改時,以及重新啓動服務器

我怎樣才能Javascript功能來在生產模式下運行的時候,已經rake assets:precompileRAILS_ENV=production rake assets:precompile? (另外,我對Ruby on Rails比較陌生,所以我不確定哪些文件/信息可以幫助我。)謝謝。

的application.js

// This is a manifest file that'll be compiled into application.js, which will include all the files 
// listed below. 
// 
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 
// 
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 
// compiled file. 
// 
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 
// about supported directives. 
// 
//= require jquery 
//= require jquery_ujs 
//= require jquery.turbolinks 
//= require bootstrap/bootstrap 
//= require theme/bootstrap.min 
//= require theme/flexslider 
//= require theme/index-slider 
//= require theme/jquery.countdown.min 
//= require theme/jquery.isotope.min 
//= require theme/theme 
//= require_tree . 
+0

你是否在application.js文件中需要它 – xiaoboa

+0

是的,我在application.js中包含了主題/索引滑塊。我已經添加了application.js。此外,我還看到了Chromes開發工具中javascript資源中的TestTestTest警報。 –

回答

1

我發現,問題出在文件的application.js。我已經將bootstrap手動添加到了我的項目中,並添加了一個boostrap主題。我發現無論出於何種原因,// = require bootstrap/bootstrap行不應該包含在我選擇的主題之上。

1

您需要編譯資產爲您的生產以及

rake assets:precompile RAILS_ENV=production 
+0

我嘗試過,但沒有任何效果。 JavaScript仍然沒有運行。我也確認我想運行的文件位於已編譯的application.js文件中。 –

+0

你能看到你的js文件包含在你的html頁面上嗎? – Abk

+0

是的,我可以。所有的文件都被編譯成一個文件。我已經在生產中關閉了壓縮而沒有任何效果。 JavaScript仍然不能在部署模式下運行。 –