DEV Community


Discussion on: Adding Custom JavaScript in Rails 6

johnviviano profile image
John Viviano

Thanks for this article. It was helpful. Changing the declaration of your JavaScript function may simplify things a bit:

// in your html
<a href="#" onclick="dosmth()">dosmth</a>

// javascript/packs/custom.js
window.dosmth = function() {

// I don't think you need the export default dosmth;
// export default dosmth;

// In your javascript/packs/application.js I don't think you need the corresponding declarations:

// import dosmth from './custom'
// window.dosmth = dosmth