I attempted to integrate the Sweet Alert 2 java-script library for customising standard alert boxes into a Rails 7 application, but I received the following error message: "Swal is not defined." I'm using Ruby 3 and Rails 7.
I initially attempted to use the "sweet-alert2-rails" gem in my Rails application, but there are no current updates available. I therefore attempted to accomplish this using import map, and I did so by running the following line.
bin/importmap pin sweetalert2
On top of that, I added the lines below to the application.js
import Swal from "sweetalert2"
I encountered the aforementioned problem when attempting to use "Sweet Alert 2" in my view files.
Swal.fire(
'Good job!',
'You clicked the button!',
'success'
)
To integrate Sweet Alerts into my Rails application, I used these links.