简体   繁体   English

未捕获的ReferenceError:未在Rails 5的控制台中定义jQuery

[英]Uncaught ReferenceError: jQuery is not defined in console for Rails 5

I just installed the jQuery UI for my Ruby on Rails application. 我刚刚为Ruby on Rails应用程序安装了jQuery UI。 It runs Rails 5. I have looked at all the similar posts, but they do not apply to my case. 它运行着Rails5。我已经看过所有类似的文章,但是它们不适用于我的情况。

My page renders just fine, but in the Chrome dev tools console, I get this error: 我的页面呈现得很好,但在Chrome开发者工具控制台中,出现此错误:

在此处输入图片说明

I have rearranged the application.js file all kinds of ways and still get the same error. 我已经以各种方式重新排列了application.js文件,但仍然收到相同的错误。 This is the file: 这是文件:

// 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

Per the comment above, try the require jquery at the top. 根据上面的评论,尝试顶部的require jquery。

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

jquery-ui requires you to have the default JQuery loaded beforehand. jquery-ui要求您事先加载默认的JQuery。 That's the reason you are seeing all those errors, as jquery-ui has references to it throughout its code, hence its throwing exceptions. 这就是您看到所有这些错误的原因,因为jquery-ui在整个代码中都引用了它,因此抛出了异常。 Your application.js should look like this instead: 您的application.js应该看起来像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM