Show text with sinatra ruby

2024-01-17 ruby sinatra javascript

Example that keeps showing the content of textfile(/tmp/message.txt) on the browser. It automatically reloads the content every seconds which may not be the best solution(^^;

sinatra.rb

get '/' do
  @m = IO.read("/tmp/message.txt") || ""
  erb :index
end

views/index.erb

<html>
<body>
  <p id="message"><%= @m %></p>
  <p id="ts"></p>
  <style>
    #message { font-size: 100px; }
  </style>
  <script>
    setTimeout(location.reload(),1000);
  </script>
</body>
</html>