Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 强制定期呼叫遥控器立即开火_Ruby On Rails_Ajax - Fatal编程技术网

Ruby on rails 强制定期呼叫遥控器立即开火

Ruby on rails 强制定期呼叫遥控器立即开火,ruby-on-rails,ajax,Ruby On Rails,Ajax,我有一个 periodically_call_remote 我希望立即启动(就像代码在没有setTimeout的情况下出现一样)并定期调用。有没有一个很好的方法来使用PCR,或者我必须自己滚动 如果有帮助的话,我会使用jQuery/jRails。这不是一个完美的解决方案,但是远程函数会在第一毫秒内被调用 def periodically_call_remote_starting_now(options = {} ) page.call("starting_now_count = 0")

我有一个

periodically_call_remote
我希望立即启动(就像代码在没有setTimeout的情况下出现一样)并定期调用。有没有一个很好的方法来使用PCR,或者我必须自己滚动


如果有帮助的话,我会使用jQuery/jRails。

这不是一个完美的解决方案,但是远程函数会在第一毫秒内被调用

def periodically_call_remote_starting_now(options = {} )
  page.call("starting_now_count = 0")
  periodically_call_remote ( options.merge(:frequency => 0.001, :condition => "++starting_now_count == 1"))
  periodically_call_remote (options)
end

总有一个加载解决方案

在已定义主体标记的视图中:

<body onload="<%= remote_function( ==same options used with periodically_call_remote==) %>" >


它将在加载时调用remote函数,并让与定期调用有关的魔法在所需的时间间隔内调用它。看看时钟是如何在onload启动的大致相同的时间,相对于周期性的调用远程间隔启动的。你应该得到你想要的功能。

好吧,我没有足够的声誉评论Kandaboggu的帖子,所以写我的评论作为回答

我最喜欢Kandaboggu的反应,但是为了让helper方法发挥作用,我不得不做一些改变。我想出的代码如下。如果我的改变是无意义的,请随意投票否决我(但更好的是,发表评论并让大家知道原因)。我对Kandaboggu代码的更改如下:

def periodically_call_remote_starting_now(options = {})    
  result = ""
  result << javascript_tag("starting_now_count = 0;")
  result << periodically_call_remote(options.merge(:frequency => 0.001, :condition => "++starting_now_count == 1"))
  result << periodically_call_remote(options)
end
def定期调用远程启动(选项={})
result=“”
结果“++现在开始\u计数==1”))

结果是,这将称之为onclick,但我知道你的意思:P我最终使用了remote_函数solution.oops。我从其他代码中复制了onclick语句,但忘了将其更改为onload。
undefined local variable or method `page' for #<ActionView::Base:0x7fc37a6e2658>