0

I have a Rails view with 3 partials. In my index.html.erb I have the following javascript to refresh the page automatically via JS.

index.html.erb

<div id="newstatus">
  <%= render 'newstatus' %>
</div>
<div id="newunitdisplay">
  <%= render 'newunitdisplay' %>
</div>
<div id="unitalerts">
  <%= render 'unitalerts' %>
</div>

<script>
  $(function() {
    setInterval(function(){
      $.getScript("/mdt");
    }, 10000);
  });
</script>

index.js.erb

$("#newunitdisplay").html("<%= escape_javascript render("newunitdisplay") %>");
$("#newstatus").html("<%= escape_javascript render("newstatus") %>");
$("#unitalerts").html("<%= escape_javascript render("unitalerts") %>");

What I would like to do is to only refresh 2 of the 3 partials. newunitdisplay and newstatus. I have some audio_tag statements in unitalerts that I don't want to refresh otherwise the sounds will continuously look every 10 seconds.

My question is what would the javascript look like to refresh just the two partials for newunitdisplay and newstatus?

It's the only way I can think of that will keep the audio_tags I have from looping every 10 seconds.

Thanks in advance.

nulltek
  • 3,247
  • 9
  • 44
  • 94
  • What don't you simply delete `$("#unitalerts").html("<%= escape_javascript render("unitalerts") %>");` from `index.js.erb`? – UKatz Dec 31 '13 at 17:38
  • I've tried your suggestion before posting my question. When I remove it the partial will not load. I need to figure out some JS to refresh only 2 of the 3 partials every 5 seconds instead of the whole index/controller. – nulltek Dec 31 '13 at 18:10
  • To do that you will need to return a json with the HTML of each partial and then put it in the right place on the page, because render is done server-side by ruby. If you show your controller I can help further. – UKatz Dec 31 '13 at 21:20

0 Answers0