title: How to execute custom javascript functions in Rails 6
body: <p>With the arrival of Webpacker to Ruby On Rails, I can't find a way to use my JavaScript functions.</p>
  
  <p>I have a file called <code>app-globals.js</code> with a function to test:</p>
  
  <pre class="lang-js prettyprint-override"><code>function alerts() {
    alert("TEST")
  }
  </code></pre>
  
  <p>Then I want to use it in one of my views:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;% = button_tag 'Button', type: 'button', onClick: 'alerts ()'%&gt;
  </code></pre>
  
  <p>But when I press the button, this error is shown in the browser console:</p>
  
  <p><code>ReferenceError: alerts is not defined</code></p>
  
  <ol>
  <li><p>I placed the <code>app-globals.js</code> file in <code>"app/javascript"</code> and in <code>"app/ javascript/packs/application.js"</code> I placed require ("app-globals").</p></li>
  <li><p>I moved app-globals.js to <code>"app/javascript/packs"</code> and removed the require ("app-globals") from <code>application.js</code>.</p></li>
  </ol>
  
  <p>With either case, an error still appears.</p>