I am trying to add this: https://github.com/Alex-D/Cookies-EU-banner to my rails 6 site. It ought to be easy, but there is something I have missed, and I can not figure out, what it is.
This is what I have done:
- yarn add cookies-eu-banner (no problem).
- insert this div at the beginning of the body part (no problem - done with a partial).
<div id="cookies-eu-banner" style="display: none;">
By continuing to visit this site, you accept the use of cookies by Google Analytics for statistical purposes.
<a href="./read-more.html" id="cookies-eu-more">Read more</a>
<button id="cookies-eu-reject">Reject</button>
<button id="cookies-eu-accept">Accept</button>
</div>
- insert this div just before the end of the body part (also done with a partial).
<%= javascript_pack_tag '../src/cookies-eu-banner' %>
<script>
new CookiesEuBanner(function () {
// Your code to launch when user accept cookies
});
</script>
in application.js I have added this line: import('src/index')
in app/javascript/src/index.js I have added this line: import 'cookies-eu-banner'
I have copied the cookies-eu-banner.js script to the app/javascript/src folder.
Then precompiled assets, done bin/webpack and restarted the server.
However on refreshing the page, I still get either an errormessage saying that: "CookiesEuBanner is not a function", or: "Uncaught ReferenceError: cookiesEuBanner is not defined"
Any suggestions to what I have missed are more than welcome.
Thanks in advance