Question

In my Rails App, I have a javascript Timer in one page. When using turbolinks, the Timer object would persist between pages.

So, when user starts the timer in the timer.html.erb and go to another page and change back, the timer is still running(persistes), instead of starting again.

I'd like to show you my example. But where to put it? JS fiddle? Heroku?

Notice: I've tried that, if I turn the turbo links off, everthing would be fine.

Was it helpful?

Solution

Instead of removing Turbolinks, I would use their events to reload the timer each time the page loads:

#app/assets/javascripts/application.js
var timer = function() {
    //timer init
};

$(document).ready(timer);
$(document).on('page:load', timer);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top