Home:ALL Converter>sweetalert2 with rails 6

sweetalert2 with rails 6

Ask Time:2019-07-05T06:07:28         Author:FDI

Json Formatter

I'm using sweetify gem to add sweetalert2 to my rails 6 app, but I'm getting this error

Uncaught ReferenceError: Swal is not defined

I added the following code to the environment.js file

environment.plugins.append('Provide', new webpack.ProvidePlugin({
  sweetalert2: 'sweetalert2/dist/sweetalert2.all',
  Swal: 'sweetalert2/dist/sweetalert2.all'
}));

and I do require it in the application.js file as the following

require("sweetalert2")

the sweetify gem add the below code before the end of the tag

<script>
      Swal.fire({"showConfirmButton":true,"timer":null,"allowOutsideClick":false,"confirmButtonText":"Try again","type":"error","text":"there was a problem saving your Information, please try again","title":"Oops..."})
    </script>

I don't know what I'm missing.

Any help is highly appreciated

Author:FDI,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/56894623/sweetalert2-with-rails-6
Leid :

try to do this : \n\nyarn install sweetalert2\n\n\nAnd\n\nimport Swal from 'sweetalert2';\nwindow.Swal = Swal;\n",
2020-05-27T08:25:35
yy