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 jquery_ujs
//= require_tree .
views/layouts/application.html.erb has
<%= javascript_include_tag "application" %>
A simple Javascript test in test.js:
if (jQuery) {
alert('Jquery is loaded')
} else {
alert ('Jquery is not loaded')
}
gives me an alert telling me that jQuery is indeed loaded.
However, no jQuery commands will work, even basic ones are unresponsive:
$(document).ready(function(){
$("a").click(function(event){
alert("Thanks for visiting!");
});
});
I’ve tried everything — even reincluding jQuery through the Google API. Any ideas on what might be going on?
Fixed it!
in application.html.erb, I changed the ordering of these two lines from:
to:
Now it works! I’m not quite sure why though, can anybody explain?