Skip to content

Instantly share code, notes, and snippets.

@kevintyll
Created December 4, 2009 13:51
Show Gist options
  • Save kevintyll/249020 to your computer and use it in GitHub Desktop.
Save kevintyll/249020 to your computer and use it in GitHub Desktop.
#This will store the PeriodicalExecuter in a variable. In order to set
#the name of the variable, you can pass in a :variable option. By
#default, it will use 'poller'.
#
#So you can do:
#
#periodically_call_remote(:url => some_url, :update => 'some_div',
#:variable => 'my_var')
#
#And when you want to stop the polling, you can inject the following line
#of javascript into your page:
#
#<script>
# my_var.stop();
#</script>
def periodically_call_remote(options = {})
variable = options[:variable] ||= 'poller'
frequency = options[:frequency] ||= 10
code = "#{variable} = new PeriodicalExecuter(function()
{#{remote_function(options)}}, #{frequency})"
javascript_tag(code)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment