65

I am getting the following error even if I have jquery-ui in my application.js file

couldn't find file 'jquery-ui' (in /home/jeff/work/projects/a/media/app/assets/javascripts/application.js:14)

application.js

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery.validate.min

Can anybody help me?

user229044
  • 232,980
  • 40
  • 330
  • 338
Sam
  • 5,040
  • 12
  • 43
  • 95

6 Answers6

120

Use specific version of gem "jquery-rails", "~> 2.3.0" as later version of gem has deleted the ui part.

or

you can use gem "jquery-ui-rails" for jquery-ui . For more information please visit the git repository

To require all jQuery UI modules, add the following to your application.js:

for version 5.0 and more it has been changed. Please follow the link

application.js:

//= require jquery-ui

application.css:

/*
 *= require jquery-ui
 */

For lesser version than 5.0 we need to write below format

application.js:

//= require jquery.ui.all

Also add the jQuery UI CSS to your application.css:

application.css:

/*
 *= require jquery.ui.all
 */

Hope this could help you

Debadatt
  • 5,935
  • 4
  • 27
  • 40
  • If I put gem "jquery-ui-rails" in my Gemfile,then error comes as couldn't find file 'jquery' – Sam Jul 24 '13 at 10:40
  • 9
    i found that i had to restart the app for the addition of jquery-ui-rails to take. steps i took: 1. added gem 'jquery-ui-rails' to the Gemfile. 2. ran bundle install. 3. added requires to application.js and application.css 4. restarted rails app. working well for me now. – Andrew Sep 05 '13 at 13:57
  • This answer is no longer accurate with current releases of jquery-ui-rails -- `jquery.ui.all` is no more. – Charles Duffy Oct 14 '14 at 19:36
  • 1
    Oh ! To all users. Be carefull between the minus sign and the dot sign between jquery.ui and jquery-ui between these two version. I have lost so much time on this tiny stupid sign. By the way, thanks for the response. – Ratinahirana Apr 02 '16 at 12:43
  • I wanted to upgrade `jquery-rails` to `~> 4.0.4` because Bundle Audit told me 2.x had vulnerabilities. Installing `jquery-ui-rails` worked for me. Thanks – PJSCopeland May 22 '17 at 23:40
38

I think you are using new version (your version > 2.3.0) of jquery-rails.

jQuery UI has been removed from jquery-rails gem,

  • ≤ jquery-rails v2.3.0 still have jQuery UI
  • ≥ jquery-rails v3.0.0 jQuery UI removed

Take a look this commit.

If you are using ≥ jquery-rails v3.0.0 or latest version of jquery-rails

You should use jquery-ui-rails gem for using jquery UI in rails, https://github.com/joliss/jquery-ui-rails.

In your Gemfile, add:

gem 'jquery-ui-rails'

and run bundle install

  1. v2.3.0 < your version ≤ v4.2.1

    And put this into application.js

    //= require jquery.ui.all
    

    then put this into application.css

    *= require jquery.ui.all
    
  2. ≥ jquery-ui-rails v5.0.0 or latest version

    And put this into application.js

    //= require jquery-ui
    

    then put this into application.css

    *= require jquery-ui
    

    or to use specific modules read this

Don't forget restart your server.

If you are using ≤ jquery-rails v2.3.0

see my answer here https://stackoverflow.com/a/16996710/1297435 for use gem 'jquery-rails', "~> 2.3.0"

Community
  • 1
  • 1
rails_id
  • 8,120
  • 4
  • 46
  • 84
  • 1
    Your changes here seem more future-proof than a specific version of the gemfile. Thanks for this answer. – Broam Apr 26 '14 at 13:55
  • I couldn't get it to work with `gem 'jquery-rails', "~> 2.3.0"` so ended up deleting jquery-rails and only using `gem 'jquery-ui-rails'` in that case you also need to delete `//= require jquery` `//= require jquery_ujs` from application.js, otherwise you might still get an error. That did the trick for me... – PSR Dec 17 '14 at 21:33
9

The rails 4 answer:

add to gemfile.rb:

gem 'jquery-ui-rails'

add to application.js:

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

to add a specific module:

//= require jquery
//= require jquery-ui/yourmodulename
//= require jquery_ujs

I'm not sure if restarting your server is explicitly required but it never hurts anything.

Joe Susnick
  • 6,544
  • 5
  • 44
  • 50
  • 1
    Yes! Restarting the server fixed it for me. – Adam Jul 17 '14 at 20:50
  • Note when requiring modules that what used to be say //= require jquery-ui/draggable is now //= require jquery-ui/widgets/draggable ie. an extra 'widgets' level – giorgio Apr 24 '18 at 02:18
4

I know its a noob mistake but I found this very frustrating and always forget to restart my app after I have installed something new.

Make sure to restart your rails server after you have followed the instructions above and it should work perfectly.

doz87
  • 591
  • 6
  • 15
1

Kind of a noob mistake, but if it helps anyone..

I added jQuery-ui.js in my assets and then added the gem. Then deleted the js from assets, but my IDE also deleted the same files from the gem.

To resolve, first remove the gem and then run,

bundle clean --force

and then

bundle install
ronnygeo
  • 106
  • 3
0

It could just be a matter of restarting WEBrick or any other server you might be using so it picks up the new assets. For WEBrick just go to your terminal window where your server is running and CTRL-C to terminate the process, after that just restart it again using rails s or whatever the command to start your server is.

rii
  • 1,578
  • 1
  • 17
  • 22