Created
December 4, 2009 13:51
-
-
Save kevintyll/249020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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