我可以在本地生产上运行jQuery,rails s -e production
上运行jQuery,但是当将同一个项目部署到Heroku时,jQuery无法正常工作,并且在控制台中显示错误
“未捕获的ReferenceError:未定义$”
。我没有使用Turbolinks,所以除了
,我不需要做任何其他事情$(document).ready(function() {
//everything js goes here });
正常的JavaScript可以工作。
我使用$("#element-id")
在Chrome的控制台中进行了检查,它提供了该元素的详细信息,因此我认为正在加载jQuery。还是Chrome控制台默认使用jQuery?
我的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, or any plugin's
// vendor/assets/javascripts directory 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. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require Chart.min
//= require_tree .
本地生产环境应该与Heroku一样吗?为什么在Heroku和本地生产环境中行为不同?