【问题标题】:Why is jquery-rails not loading?为什么 jquery-rails 没有加载?
【发布时间】:2014-06-18 05:26:05
【问题描述】:

我已尝试在我的 rails 应用程序 (3.2) 中手动添加 jquery,它可以正常工作。

application.html.erb

<script src="/js/jquery-1.9.1.js"></script>
<script src="/js/jquery-ui-1.10.3.custom.js"></script>

现在我尝试使用 rails-jquery gem 替换它,css 似乎加载了,但是 js 不起作用。我错过了什么?我该如何调试? Gem 文件(后跟 bundle install)

gem 'jquery-rails'

application.html.erb

<%= javascript_include_tag "application" %>

应用程序.js

//= require bootstrap
//= require jquery
//= require jquery_ujs
//= require jquery-ui

我的 Gemfile.lock 看起来像这样。

specs:
  jquery-rails (2.0.2)
    railties (>= 3.2.0, < 5.0)
    thor (~> 0.14)
  jquery-ui-rails (4.0.5)
    railties (>= 3.1.0)

【问题讨论】:

  • 如果您使用任何自定义布局,那么您的布局中有 javascript_include_tag 吗?
  • 是的,我知道-抱歉-忘了提。
  • 即使你使用 gem,你也需要有 javascript_include_tag。它基本上告诉 Rails 在你的 application.js 中包含你需要所有 js 文件的地方
  • 你在使用gem时没有那个标签?
  • 是的 - 我的意思是,我的 application.js 文件中已经有了标签。我只是忘了在原始问题中提及。我现在已将其添加到我上面的代码中。问题依然存在。

标签: javascript jquery ruby-on-rails ruby-on-rails-3


【解决方案1】:

根据聊天讨论,问题是 安装的 jquery 与插件使用的版本不同,因此出现错误。

您可以通过

安装特定版本的 jquery-rails
gem 'jquery-rails', '~> version'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-06
    • 2016-12-14
    • 1970-01-01
    • 2018-08-15
    • 2012-02-06
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多