title: Execute javascript everytime a route is hit in rails
body: <p>When my page loads for the first time the code in /assets/javascript/home.js executes, which positions my navbar using Bootstraps affix.</p>
  
  <pre><code>$('.navbar').affix({
    offset: {
      top: function() {
        return this.bottom = $('.hero').outerHeight(true);
      }
    }
  });
  </code></pre>
  
  <p>When I go to another route such as <code>/blog</code>, I don't want this code to execute and want my static CSS to render which works great. The problem is when I got back to the home route(<code>/</code>), the JavaScript doesn't execute again and my navbar is using its natural CSS. If I refresh at this point, the page will reload fully and my navbar will be positioned correctly.</p>
  
  <p>I think the problem is because of turbo-links but I am not experienced enough with Rails to resolve this issue. Hope somebody can shed some light!</p>