Jakub Arnold
Jakub Arnold

Reputation: 87240

How can I tell if jQueryUI is being loaded properly in 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

I always get the 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
      90

Upvotes: 1

Views: 915

Answers (4)

Deborah
Deborah

Reputation: 4575

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.)

Upvotes: 0

Lavixu
Lavixu

Reputation: 1398

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.

Upvotes: 0

jasondoucette
jasondoucette

Reputation: 1156

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")

Upvotes: 1

Evan
Evan

Reputation: 6115

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.

Upvotes: 0

Related Questions