title: Rails 4 show ajax loader on remote=true form submission
body: <p>I'm new to rails and am having trouble figuring out where in the "magic" I can handle an event to show an ajax loader when my ajaxified form is submitted, and hide the loader when my ajax response is returned and displayed to the user. </p>
  
  <p>Here's what I have, where can I add a .js file or function to bind/run on click to show the loader? I know I can remove the loader in the runCMD.js file.</p>
  
  <p>Controller:</p>
  
  <pre><code>def runCMD
  
      @cmdType = params['commit'].downcase #commit is name of submit button clicked
  
      //do some stuff, removed for brevity...
      @output = //buncha stuff that happens, but returns output of the commands ran
      @outputVersions = //buncha other stuff, but sets this var
  
      respond_to do |format|
              format.js   { }
      end
  
      #render 'testServer'
  
  end
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;%= form_tag('/runCMD', :method =&gt; 'post', :remote =&gt; true) do %&gt;
      &lt;%= select("versions", "version", @outputVersions) %&gt;
      &lt;%= submit_tag "Activate", class: "run-cmd-button" %&gt;
      &lt;%= submit_tag "Stop", class: "run-cmd-button" %&gt;
      &lt;%= submit_tag "Start", class: "run-cmd-button" %&gt;
      &lt;%= hidden_field_tag 'component', @component %&gt;
  &lt;% end %&gt;
  
  &lt;br /&gt;
  &lt;div id="ajax_output" contenteditable="true" style="background-color:black;font-size:10pt;font-family:Courier New;overflow-y:auto;height:1000px;width:1180px;"&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>.js file</p>
  
  <pre><code>  $('#ajax_output').html("&lt;%= escape_javascript(render partial: 'cmdOutput', locals: { output: @output } ) %&gt;");
  </code></pre>
  
  <p>Partial</p>
  
  <pre><code>&lt;% output.each do |line| %&gt;
      &lt;% line.gsub! '[33m', '&lt;font color="yellow"&gt;' %&gt;
      &lt;% line.gsub! '[32m', '&lt;font color="green"&gt;' %&gt;
      &lt;% line.gsub! '[31m', '&lt;font color="red"&gt;' %&gt;
      &lt;% line.sub! '[0m', '&lt;font color="white"&gt;' %&gt;
      &lt;% line.sub! '[0m', '&lt;/font&gt;' %&gt;
      &lt;% line.gsub! '[0m', '' %&gt;
  
      &lt;%= raw(line) %&gt;
      &lt;br /&gt;
  &lt;% end %&gt;
  </code></pre>