2017-09-16 36 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 
相關問題