Rails 4: How to get sweet alert confirm work?

Moataz Zaitoun picture Moataz Zaitoun · Jul 17, 2016 · Viewed 8.6k times · Source

I'm a beginner with rails and I want to use Sweet Alert to replace the basic ugly confirm messages on deleting records. I've added sweet-alert gem and sweet-alert-confirm to my gem file I've done exactly what they said in the their Read Me, but It doesn't work, I can delete records but It got deleted right away without any confirm message of any kind.

Gemfile

...
gem 'sweet-alert'
gem 'sweet-alert-confirm'
...

Application.jssupported directives.

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery.turbolinks
//= require bootstrap-sprockets
//= require sweet-alert
//= require sweet-alert-confirm     
//= require_tree .

stylesheet.css

/*
 ...

 *= require_self
 *= require sweet-alert
 *= require_tree .
 */

index.html.erb

...
<%= link_to 'Destroy', ice_cream, method: :delete, data: { confirm: 'Are you sure?' } %>
...

Also, there is somethings I don't know if It worth mention, when I open firebug I find the following error.

Fire bug error

Hope you can help me, Thank you.

Answer

Moataz Zaitoun picture Moataz Zaitoun · Jul 17, 2016

Thank com unity for the great help!, But yet again I found the answer myself...

Seems there is an issue with the sweetalert gem, So

  1. I uninstalled it using

    gem uninstall sweetalert
    
  2. I installed sweetalert2 using Rails Assets Web Site By Adding the following line to my Gemfile

    gem 'rails-assets-sweetalert2', source: 'https://rails-assets.org'
    
  3. Run bundle

  4. Rearrange application.js this way

    //= require sweetalert2
    //= require jquery
    //= require jquery_ujs
    //= require turbolinks
    //= require jquery.turbolinks
    //= require bootstrap-sprockets
    //= require sweet-alert-confirm
    //= require_tree .
    
  5. Rearrange application.css this way

     *= require_self
     *= require sweetalert2
     *= require_tree .
     */
    

I kept the sweet-alert-confirm gem, And every thing worked fine. Now I find this sweet message every time I try to delete a record without adding any lines of code...

enter image description here

Note: please explain why you're voting down a question before you do.