title: JS script only works while I don't change the current page
body: <p>I'm creating a web project in Ruby on Rails. I have a <code>main.js</code> file stored inside <code>/app/assets/javascripts/</code>, in which I've developed a little script to reset the forms.</p>
  
  <p>The script works perfectly just while I don't surf around the web. If I change the current page, the script doesn't work anymore. To get it work again, I have to reload the page through the browser (using <kbd>Cmd</kbd>+<kbd>R</kbd> or <kbd>F5</kbd>).</p>
  
  <p>The <code>main.js</code> script is supposed to be compiled and it should be available in all the pages in the project, isn't it?</p>
  
  <p>What's wrong?</p>
  
  <p>The code in <code>main.js</code>:</p>
  
  <pre><code>// Get rid of data in forms
  jQuery.fn.reset = function () {
  $(this).find("input, textarea, select").each (function() {
      if ($(this).is(':checkbox')) {
          $(this).prop('checked', false);
      }
      else {
          if (!$(this).is(':hidden') &amp;&amp; !$(this).is(':submit')) $(this).val('');
      }
  });
  }
  
  $(document).ready(function() {
  
      // Cancel button in forms
      $(".cancel").click(function() {
          $(document).reset();
      })
  });
  </code></pre>
  
  <p>Application.js:</p>
  
  <pre><code>//= require jquery
  //= require jquery_ujs
  //= require bootstrap
  //= require turbolinks
  //= require_directory .
  </code></pre>