當我的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:precompile
和RAILS_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 .
你是否在application.js文件中需要它 – xiaoboa
是的,我在application.js中包含了主題/索引滑塊。我已經添加了application.js。此外,我還看到了Chromes開發工具中javascript資源中的TestTestTest警報。 –