title: Loading gif on link_to with ajax rails 3.2
body: <p>I have a link_to that renders slow due to parsing a lot of JSON data in the show. I'm having issues implementing a loading gif on the index page while the destination page finishes loading. It shows the loading icon, but does not go to the show page and finishes its animation.</p>
  
  <p>CSS</p>
  
  <pre><code>#loading-indicator {
    position: absolute;
    left: 10px;
    top: 10px;
  }
  </code></pre>
  
  <p>Index view </p>
  
  <pre><code>&lt;img src="/images/loading.gif" id="loading-indicator" style="display:none" /&gt;
  &lt;% @list.each do |l| %&gt;
  &lt;%= link_to l.name, list_path(l), :remote =&gt; true %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>script</p>
  
  <pre><code>&lt;script&gt;
  $(document).ajaxSend(function(event, request, settings) {
    $('#loading-indicator').show();
  });
  
  $(document).ajaxComplete(function(event, request, settings) {
    $('#loading-indicator').hide();
  });
  &lt;/script&gt;
  </code></pre>