I believe jQuery doesn't work on other pages than the one you just installed. For example, when I type localhost:3000/, in the '/' directory all jQuery works. But when I click to a link created by Rails as
<%= link_to "Example Link", news_path %>
The page correctly loads, but the jQuery doesn't work. My jQuery codes are as stated:
$(function() {
console.log( "pageloaded" );
....
$('.up').click(function(){
.....
});
});
In Rails 4 turbolinks
is active by default.
That means, that $(document).ready()
is not executed, when you load a new page.
turbolink
fires a new event page:load
. You can use this to run your javascript code:
$(document).on('page:load', your_start_function);
There is an excelent rails cast on turbolinks
https://github.com/kossnocorp/jquery.turbolinks
This gem binds jQuery.ready function with Turbolinks listen event page:load, therefore the solution is supposed to be solved if you are using Turbolinks with Rails 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With