When rails generates app / assets / javascripts / application.js, it automatically includes this line:
Indicates that the rails should include every file in this directory in application.js, which is called by default in the header of your page. This line in the foobar.js file:
$(document).ready(function(){ getvalue(); setInterval('getvalue()', 2000); });
tells javascript to run this code every time the DOM loads. This is why your code works on every page.
To prevent this, you have several options (see this post for some ideas), but what could be easiest is to look for an element in the DOM that is only on the pages where you want it to be executed, approximately So:
$(document).ready(function(){ if( $("#element-id-only-on-foobar-pages").is(":visable") ) { getvalue(); setInterval('getvalue()', 2000); } });
source share