Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is jQuery not loading in my Rails 3.2.3 app?

Up until yesterday jQuery was loading just fine in my Rails app. I was playing around with getting the debugger/ruby-debug gem installed. As you are probably aware there are issues with the debugger gem in Rails 3 and I was unsuccessful in getting the dependancies installe so I removed the gems from my Gemfile. Since then when loading my site jQuery is not loading. These are the messages I see in console:

assets/jquery_ujs.js?body=1:377Uncaught ReferenceError: jQuery is not defined
bootstrap-transition.js:24Uncaught TypeError: undefined is not a function
bootstrap.js:3Uncaught ReferenceError: jQuery is not defined
welcome:210Uncaught ReferenceError: $ is not defined

And here is my application.js file:

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .

If I load jQuery explicitly in layouts/application.html.erb, like so, it works:

<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" %>
<%= javascript_include_tag "application" %>

Any thoughts on what I can do to resolve this and get jQuery loading again? Looking in .rvm/gems/ruby-1.9.3-p125/gems/jquery-rails-2.0.2/vendor/assets/javascripts I can see jquery.js and jquery.min.js are still there.

like image 979
Ryan Arneson Avatar asked May 11 '12 14:05

Ryan Arneson


2 Answers

Thanks @Djj. Re-ordering my application.js tree seems to have resolved the issue. Here is my revised tree:

//= require jquery_ujs
//= require jquery
//= require twitter/bootstrap
//= require jquery.placeholder
//= require_tree .
like image 89
Ryan Arneson Avatar answered Sep 20 '22 06:09

Ryan Arneson


In my case the problem was due to asynchronously loading the javascript file.

<%= javascript_include_tag "application", :async => true %>

Switching back to

<%= javascript_include_tag "application" %>

solved the issue.

like image 36
Hartwig Avatar answered Sep 23 '22 06:09

Hartwig