Working with Turbolinks and jQuery in Rails 4
I had a huge problem getting my JavaScript to fire on page reloads, and after many hours(days?) of trying to get this to work, I found the solution below:
var ready = function pageLoad() {
//(all your callback functions here)
$('.class').on('click', function(event) {
.....
})
}
$(document).ready(ready)
$(document).on('page:load', ready)
This worked for me (using Rails 4.1.0, Ruby 2.0.0). Make sure to use .on(), instead of the direct .click().
Written by Alexandra Mirtcheva
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#