Can't find 'jquery-ui' Rails 3.2

2020-02-29 08:22发布

问题:

I have been looking everywhere to figure out this problem. I already downgraded the jquery-rails gem to 2.3.0 in my gemfile. But when I include jquery-ui in application.js I still get the Sprokets::FileNotFound error.

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

This is my application.js 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, 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 .

I am dying to find out why this isn't working...

回答1:

If you are using the jquery-ui-rails gem, you need to use require jquery.ui.all instead of require jquery-ui. If you don't want to use the gem, make sure that you have a jquery-ui.js file in your app/assets/javascripts folder.

UPDATE

As of version 5.0.0, use require jquery.ui.



回答2:

I tried downgrade jquery-rails on my application, That works fine.

  1. Put gem 'jquery-rails', "~> 2.3.0" to Gemfile
  2. Remove Gemfile.lock -> rm Gemfile.lock
  3. Run bundle install
  4. Put //= require jquery-ui to 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)

Could you post your Gemfile ?



回答3:

I had a similar issue. The problem was not related to the existing gems but rather with the cached version of them.

The following steps solved the issue for me:

  1. Specify the actual versions for the affected gems
  2. Clean the asset pipeline by running rake assets:clean
  3. Clean your browser's cache
  4. Start the server again

This process won't be the same for everyone as the issue here is tied to the cached version of the gems, as I've already mentioned.

At least it should help find the solution.