views:

563

answers:

2

I have periodically_call_remote updating a div (main_div) in my web app. This main_div contains links that the user can click that invokes an action that overwrites data within main_div.

My problem is that the timer is running on the periodically_call_remote function and even though the user has navigated away from the page, that function call still wants to return. If the main_div is present on the page the function call wipes out the data that was currently being displayed. If the main_div is not on the page then the javascript returns an error dialog.

So, my question is, when the user navigates away from the div that is periodically being updated, how do I stop the function call?

A: 

You would want to setup the layout/template to conditionally enable the updater

diclophis
+5  A: 

This thread: http://www.ruby-forum.com/topic/119372 provided the answer that I needed.

Essentially it boils down to overriding periodically_call_remote in the application_helper.rb file to put the PeriodicalExecutor into a js variable.

Then, you can call poller.stop(); whenever you want to cancel the calls.

salt.racer