I regularly contribute to a ruby project called Octobox. I’ve been mucking around with an auto refresh feature, which simply reloads the page every 120 seconds.
https://raw.githubusercontent.com/GiacomoLaw/octobox/9648453e201b98a2c8e9bbb0acfb9d68af912b28/app/views/notifications/index.html.erb
Would it work? I know it would in .html, but this is a .html.erb file, so I’m not too familiar with it.
Thanks in advance!
If you want the page to be refreshed after EVERY 120 seconds, you could just write a setTimeout
in the html page.
In your head
section do this
<head>
<meta http-equiv="refresh" content="120" />
<!-- Added new code below -->
<script>
var RELOAD_AFTER = 2 * 60 * 1000; // 120 seconds or 2 minutes
setTimeout(function(){
window.location.reload();
}, RELOAD_AFTER );
</script>
</head>
1 Like
This looks great! Thank you!
Is there any way I can apply it only to part of the ruby site, for example this div tag?
<div class="blankslate blankslate-spacious blankslate-clean-background">
<%= octicon 'mail-read', height: 32, class: 'blankslate-icon' %>
<%= octicon 'thumbsup', height: 32, class: 'blankslate-icon' %>
<h3>You're in the clear!</h3>
<p>There are no notifications that need your attention.</p>
<% if current_user.last_synced_at %>
<p class='text-muted'>
<small>Last sync: <%= time_ago_in_words current_user.last_synced_at %> ago</small>
</p>
<% end %>
</div>
I’m afraid that’s not possible with the approach I shared previously. It will reload the entire page. If you want particular section of your page to be updated after some interval, then you need to write a separate javascript to take care of that.
I’m not sure how ruby will help here though.
1 Like