Reputation: 676
I have a jquery confirmation on a delete link. The confirmation pops up just fine when you click on the link, however, it pops up a second time when you click 'OK'. I can not figure out why. Other than having to click 'OK' twice, the method works fine and the post gets deleted.
show.html.haml
%h1= @post.title
%p= @post.description
%p= link_to 'Back', root_path
%p= link_to 'Edit', edit_post_path
%p= link_to 'Delete', @post, method: :delete, data: { confirm: 'Are you sure you want to delete this Post?' }
posts_controller.rb
class PostsController < ApplicationController
before_action :find_post, only: %i[show edit update destroy]
.
.
.
def destroy
@post.destroy
redirect_to root_path, notice: 'Post successfully deleted.'
end
.
.
.
def find_post
@post = Post.find(params[:id])
end
end
Gemfile
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.7'
gem 'coffee-rails', '~> 4.2'
gem 'haml', '~> 5.0', '>= 5.0.4'
gem 'jbuilder', '~> 2.5'
gem 'jquery-rails', '~> 4.3', '>= 4.3.1'
gem 'puma', '~> 3.7'
gem 'rails', '~> 5.1.4'
gem 'sass-rails', '~> 5.0'
gem 'simple_form', '~> 3.5'
gem 'sqlite3'
gem 'turbolinks', '~> 5'
gem 'uglifier', '>= 1.3.0'
application.js
//= require jquery
//= require jquery_ujs
//= require rails-ujs
//= require turbolinks
//= require_tree .
Upvotes: 3
Views: 598
Reputation: 340
remove jquery_ujs from your application.js as rails_ujs is enough for later rails version.
Upvotes: 6