为什么我在Rails中两次获得JQuery警报?

时间:2018-01-05 12:37:49

标签: jquery ruby-on-rails

我在删除链接上有一个jquery确认。当您点击链接时,确认弹出正常,但是,当您点击“确定”时,它会再次弹出。我无法弄清楚为什么。除了必须点击“确定”之外两次,方法工作正常,帖子被删除。

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 .

1 个答案:

答案 0 :(得分:2)

从您的application.js中删除jquery_ujs,因为rails_ujs足以用于以后的rails版本。