Reputation: 317
I have a bot running an infinite loop in rails. I want to have things in the code periodically print to the view page as its running. Since I am having the bot run on an infinite loop I need some way to asynchronously load the page that will output the periodic updates of its actions. What is the best way to do this in rails?
Upvotes: 0
Views: 312
Reputation: 139
Let me cover 3 different approaches you can take:
Javascript refresh would be simply adding:
setTimeout(function(){
window.location.reload(1);
}, 5000);
or
<meta http-equiv="refresh" content="5; URL=http://www.yourdomain.com/yoursite.html">
as discussed on the question located at: How to reload page every 5 second?
For websockets you can do a direct connection. We use https://github.com/websocket-rails/websocket-rails for our production environment.
Finally for a dashboard you may want to consider: https://github.com/gottfrois/dashing-rails It is phenomenally easy to setup and get going. It does pump the data right to the client but allows you to skip a lot of the nitty gritty and just get running. As a warning, we had issues mixing this with other items and that is why we do not use it on production.
Upvotes: 1