title: How to refresh the browser with JS after clicking a link_to tag in a Rails app
body: <p>I'm trying to refresh the browser after the user clicks a link to an action that updates the database. </p>
  
  <p>I want to avoid using redirect_back to prevent being sent back to the top of the screen after reload so I'm adding a JS click listener to the link_to tag with a code like this:</p>
  
  <pre><code># in my view
  &lt;h5 class='my-link'&gt;&lt;%= link_to 'vote', vote_path' %&gt;&lt;/h5&gt; 
  
  # at the bottom of my application layout
  &lt;script&gt;
    $('.my-link').click(function (event) {
      window.location.reload(true);
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>The JS code listener works OK in that if I click on any section of the h5 element the page will reload. However, when I click in the link the application will go to the relevant controller#action but the page wont reload. </p>
  
  <p>I'm assuming I'm missing a way to execute first the link action and then force the refresh. So at click the app records a vote and then JS force a reload. Can you see any way I can achieve this? Thanks.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I some what solved this issue by adding a timer to the JS event so it gives time for the link to reach the controller and do the action and do the reload after it.</p>
  
  <pre><code>&lt;script&gt;
    $(document).ready(function() {
      $('.puke-icon, .clean-link, .comment-send').click(function() {
          setTimeout(function(){
                     window.location.reload(true); },
               50);
            });
  
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>This is probably too hacky so hopefully you can provide more elegant approaches thanks!</p>