Below is the code that will be updated without blinking the page. It is included, having at least one element on the page with the class tag require_updating. Add this piece of code to any downloadable javascript, and then add the tag anywhere on the page.
The only drawback is ONLY updating the body of the html page.
for instance
show do |my_model| ... if my_model.processing? row :status, class: 'needs_updating' do 'we are working on it...' end else row :status do 'ready' end end .... end
therefore, if the model is still being processed, you get a tag of the "needs_updating" class, because of which every 10 second call will be called by the next javascript.
jQuery(document).ready(function($) { if ($('.needs_updating').length > 0) { console.log("we need some updating soon"); var timer = setTimeout(function () { console.log("re-loading now"); $.ajax({ url: "", context: document.body, success: function(s,x) { $(this).html(s); if ($('.needs_updating').length == 0) { clearInterval(timer); } } }); }, 10000) } })
source share