With the arrival of Webpacker to Ruby On Rails, I can't find a way to use my JavaScript functions.
I have a file called app-globals.js
with a function to test:
function alerts() {
alert("TEST")
}
Then I want to use it in one of my views:
<% = button_tag 'Button', type: 'button', onClick: 'alerts ()'%>
But when I press the button, this error is shown in the browser console:
ReferenceError: alerts is not defined
I placed the
app-globals.js
file in"app/javascript"
and in"app/ javascript/packs/application.js"
I placed require ("app-globals").I moved app-globals.js to
"app/javascript/packs"
and removed the require ("app-globals") fromapplication.js
.
With either case, an error still appears.