Turbolinks: How to manually end a javascript session in Rails?

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.

Answers


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);

Need Your Help

Returning JAXB-generated elements from Spring Boot Controller

spring spring-mvc spring-boot jaxb2

I'm generating a plethora of Java files from http://www.ncpdp.org's XSD files (only available to members). After generating them, I'd like to use them in my Spring Controllers, but I'm having probl...

Instantiation problems with id

android instantiation identifier findviewbyid android-identifiers

I've followed a tutorial to realise a calculator. It seems that my buttons objects that i define, and instantiate with the ID are not instantiated because when i add a listener on them, they return a

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.