I\'m having an issue with jQuery on Rails 3.2.8. I\'ve installed the jquery-rails gem and my application.js has the following:
//= require jquery
//= require
Make sure you're including the javascript include tag before the yield
in your application.html.erb
. If you're using Bootstrap, I think the default application.rb
loads JS after the yield, which makes it necessary to wait until jQuery is loaded before running it in your views.
If that's the case and you don't want to relocate the include tag higher on the page, you can do this:
runScript();
function runScript() {
if( window.$ ) { // Make sure jquery is loaded
// your jquery code here
} else {
window.setTimeout(runScript, 100); // If not, wait 100 milliseconds and try again.
}
}