¿Cómo puedo saber si jQueryUI se está cargando correctamente en Rails 3.1?

I've been trying to get jQueryUI tabs to work on my Rails 3.1 application, but I always end up getting.

I am loading jQuery and jQueryUI from the jquery-rails gem manualy in my application.js.coffee

#= require jquery
#= require jquery-ui
#= require jquery_ujs
# more requires ...

jQuery ->
  // regular jQuery stuff

Siempre consigo el TypeError: Object [object Object] has no method 'tabs' as if jQueryUI wasn't loaded properly. Even if I try it in the console

fail in chrome console

I've checked contents of the jquery-rails gem and it is there

$ head -n 2 ~/.rvm/gems/ruby-1.9.3-p0/gems/jquery-rails-1.0.18/vendor/assets/javascripts/jquery.js 
 * jQuery JavaScript Library v1.7

$ head -n 2 ~/.rvm/gems/ruby-1.9.3-p0/gems/jquery-rails-1.0.18/vendor/assets/javascripts/jquery-ui.js
 * jQuery UI 1.8.16

Why isn't jQueryUI being loaded properly? Do I still need to set something in the app config to make it load jQueryUI? Is there any way I can check when it is being loaded and from where?

I checked the jQueryUI file itself and it actually does contain the tab definition ... proof:

$ grep tabs ~/.rvm/gems/ruby-1.9.3-p0/gems/jquery-rails-1.0.18/vendor/assets/javascripts/jquery-ui.js | wc -l

preguntado el 01 de febrero de 12 a las 14:02

I'd start by looking at the browser's debugger console (or firebug etc.) to see if the browser is actually requesting/loading jqueryUI -

@FrederickCheung I don't think that will help, since it should get compiled into the main application.js file and then get loaded as one big file -

You are sure you included the tabs-library in your jQueryUI-file? -

Only in production (in which yes, you'd obviously want to check that the big jammed together file contains jquery ui) -

4 Respuestas

I had this exact problem (except it was with sortable, not tabs) - turned out I had an old set of precompiled assets kicking around. Removing public/assets cleared the error (hat tip to "Rails 3.1 , jQuery UI does not load")

contestado el 23 de mayo de 17 a las 14:05

in terms of checking if it was loaded properly, I would recommend the plugin yepnope.js. It allows you to test conditions, load scripts in parallel, covers error handling, and has convenient callbacks.

Respondido 01 Feb 12, 18:02

In config/environments/development.rb ( or the environment file you want to edit)

  # Expands the lines which load the assets
  config.assets.debug = true

This will make rendering the page slow but page source will show up all the sources of javascript and css being loaded instead of showing one big compressed file. You can check if jquery-ui is one among them.

Also, check if jquery is being defined twice. In this case, the $ variable gets redefined and overridden and the apis might not be available in the new definition binding.

Respondido 30 Jul 13, 09:07

I had this problem with tabs and was going bananas. It turned out I needed to precompile my assets:

RAILS_ENV=production bundle exec rake assets:precompile

This fixed it for me. (I think removing contents of the public/assets folder as mentioned in the answer above would have worked, also.)

respondido 06 nov., 13:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.