Creede
Creede

Reputation: 153

Rails equivalent of setInterval?

Here's a piece of code (based on an example at W3Schools) that uses Javascript to update a page on a regular basis:

<!DOCTYPE HTML>
<html>
<head>
  <title>Timer test</title>
  <script>
  var myVar=setInterval(function () {myTimer()}, 1000);

  function myTimer() {
    var d = new Date();  
    document.getElementById("timeNow").innerHTML =  d.toLocaleTimeString();   
  }
  </script>
</head>
<body> 
  <h1>The time now is <span id="timeNow"></span></h1>
</body>
</html>

Is there an equivalent in pure Ruby/Rails that would update the "timeNow" span element on a regular schedule?

Upvotes: 1

Views: 896

Answers (1)

Cjmarkham
Cjmarkham

Reputation: 9691

Ruby/Rails are server side languages and have no effect on the client. You would need to use client side languages or send a notification to the client telling it to update, using something like SocketIO

Upvotes: 2

Related Questions