2017-09-16 60 views
1

我刚刚为我的Ruby on Rails应用程序安装了jQuery UI。它运行Rails 5.我看过所有类似的帖子,但它们不适用于我的案例。未捕获的ReferenceError:未在Rails 5的控制台中定义jQuery

我的页面呈现得很好,但在Chrome开发工具的控制台,我得到这个错误:

enter image description here

我已经重新安排了的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-ui 
//= require rails-ujs 
//= require html.sortable 
//= require turbolinks 
//= require_tree . 
//= require popper 
//= require bootstrap-sprockets 
+2

一下如果你把'// =需要其他requries前jquery'? –

+0

@maxpleaner是的,这是原因 –

回答

1

根据上面的评论,尝试在顶部需要jQuery的。

//= require jquery 
//= require jquery.turbolinks 
//= require jquery_ujs 
//= require turbolinks 
//= require_tree . 
0

jquery-ui要求您事先加载默认的JQuery。这就是你看到所有这些错误的原因,因为jquery-ui在其代码中引用了它,因此它引发了异常。你application.js应该是这样的,而不是:

//= require jquery 
//= require jquery-ui 
//= require rails-ujs 
//= require html.sortable 
//= require turbolinks 
//= require_tree . 
//= require popper 
//= require bootstrap-sprockets 
相关问题