Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 equivalent for periodically_call_remote

Seems like periodically_call_remote is deprecated in Rails 3, any ideas how to achieve the same functionality?

like image 389
Omar Ali Avatar asked Sep 07 '10 19:09

Omar Ali


3 Answers

I was searching for the right way to do it with Rails 3 but now I am confident that there is no equivalent to periodically_call_remote in Rails 3. To get the exact same functionality done with jQuery, I used:

$(document).ready(
  function(){
    setInterval(function(){
      $('#mydiv').load('/controller/action');
    }, 3000);
  });
like image 181
Omar Ali Avatar answered Oct 19 '22 05:10

Omar Ali


If you really want to use it, then you can install the legacy plugin which has this method:

http://github.com/rails/prototype_legacy_helper

Rails favors UJS now.

Check out these links for more info on UJS in Rails 3:
http://railscasts.com/episodes/205-unobtrusive-javascript
http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/

I did a short writeup on this in relation to prototype and the link_to_remote tag:
http://www.cowboycoded.com/2010/07/20/replacing-link_to_remote-with-ujs-in-rails-3-prototype/

Hope this helps!

like image 30
johnmcaliley Avatar answered Oct 19 '22 04:10

johnmcaliley


Use setInterval to periodically run a function which invokes an AJAX call. If you were doing it with jQuery, it might be something like:

var pollBackend = function() {
  $.getJSON("/foo/bar/poll");
}

setInterval(pollBackend, 5000);

This would attempt to poll the given URL for JSON data every 5 seconds.

like image 3
Chris Heald Avatar answered Oct 19 '22 05:10

Chris Heald