【问题标题】:Can't find 'jquery-ui' Rails 3.2找不到'jquery-ui' Rails 3.2
【发布时间】:2013-06-08 05:56:59
【问题描述】:

我一直在到处寻找以解决这个问题。我已经在我的 gemfile 中将 jquery-rails gem 降级到了 2.3.0。但是当我在 application.js 中包含 jquery-ui 时,我仍然会收到 Sprokets::FileNotFound 错误。

couldn't find file 'jquery-ui'
  (in /home/richard/projects/pickaxe/mini-projects/depot-app/app/assets/javascripts/application.js:14)

这是我的 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, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, 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
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_tree .

我很想知道为什么这不起作用...

【问题讨论】:

  • 您是否将jquery-ui.js 文件添加到您的项目中?
  • 你能发布捆绑安装的输出吗?
  • 不,我在安装包后没有做任何事情。我以为这是自动拍摄的..

标签: jquery ruby-on-rails ruby jquery-ui gemfile


【解决方案1】:

如果您使用的是jquery-ui-rails gem,则需要使用require jquery.ui.all 而不是require jquery-ui。如果您不想使用 gem,请确保您的 app/assets/javascripts 文件夹中有一个 jquery-ui.js 文件。

更新

从 5.0.0 版开始,使用 require jquery.ui

【讨论】:

  • 确保为您的 Rails 版本获取适当版本的 jquery-ui-rails gem。如果你得到 Rails 3.2 的 4.0 gem,你会过得很糟糕。
  • 嗨@FabrizioBertoglio,问一个单独的问题:)
  • @FabrizioBertoglio 我决定帮您检查一下,因为其他用户可能会遇到同样的错误,我认为如果我知道它不是,我有责任至少更新答案正确答案了。
【解决方案2】:

我尝试在我的应用程序上降级 jquery-rails,效果很好。

  1. gem 'jquery-rails', "~> 2.3.0" 放入Gemfile
  2. 删除 Gemfile.lock -> rm Gemfile.lock
  3. 运行bundle install
  4. //= require jquery-ui 放入application.js
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-06-08 13:16:50
 +0700
Compiled jquery-ui.js  (27ms)  (pid 7016)
Compiled application.js  (148ms)  (pid 7016)
Served asset /application.js - 200 OK (213ms)

您可以发布您的 Gemfile 吗?

【讨论】:

  • 我认为第 4 步应该是 //= 需要 jquery_ui 而不是 //= 需要 jquery-ui
  • @Starkers:你确定吗?您是否尝试过使用 //= require jquery_ui 。我尝试使用//= require jquery_id 得到错误couldn't find file 'jquery_ui'
  • 啊抱歉,我使用的是稍微不同的 gem:rubygems.org/gems/jquery-ui-rails 不过,我认为应该使用这个 gem 而不是 jquery rails 的 v.2.3.0,因为这个 gem 正在更新。恕我直言,这似乎比永远坚持旧版本更好。
  • 同上,使用最新版本和使用 jquery-ui-rails gem 用于 jquery ui 更好,但我的回答是帮助 OP,OP 使用 jquery-rails 版本 2.3.0。
【解决方案3】:

我遇到了类似的问题。问题与现有的 gem 无关,而与它们的缓存版本有关。

以下步骤为我解决了这个问题:

  1. 指定受影响宝石的实际版本
  2. 通过运行rake assets:clean 清理资产管道
  3. 清理浏览器缓存
  4. 再次启动服务器

这个过程对每个人来说都不一样,因为这里的问题与 gem 的缓存版本有关,正如我已经提到的那样。

至少它应该有助于找到解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 2013-06-07
    • 2013-03-30
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多