Emmanuel Mtali Emmanuel Mtali - 10 days ago 4x
Ruby Question

Turbolinks 5 [Loading Javascript Properly]

I am hosting a sample application to clearly elaborate by problem. Try to visit the site, then follow another page link, using browser back return to previous page then to another page using browser forward button(You can continue move back and forth) "Hope you see what i am talking about"

Code: Previous page

<h1>Form page</h1>
<div id="rating-form">
<label for="rating-form"> Rating </label>

Loading my js code using


doesn't work until full page load( as i espect). So i followed this solution

$(document).on('turbolinks:load', function() {


path: '/assets/',
scoreName: 'review[rating]',
score: function(){
return 0



resulted to the bug in sample application

Using gem 'jquery-turbolinks' from this solution doest work with turbolinks 5

So how can i handle this problem ?


You need to destroy it before page navigation:

$(document).on('turbolinks:before-cache', function() {
  // you will need to save current state (score, etc) before
  // doing this and load it during turbolinks:load