为什么我在Rails中两次收到JQuery警报? [英] Why am I getting a JQuery alert twice in Rails?

查看:78
本文介绍了为什么我在Rails中两次收到JQuery警报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在删除链接上有一个jquery确认.当您单击链接时,确认弹出窗口就很好了,但是,当您单击确定"时,第二次弹出确认窗口.我不知道为什么.除了不必单击两次确定"之外,该方法还可以正常运行,并且帖子被删除.

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 .

推荐答案

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

remove jquery_ujs from your application.js as rails_ujs is enough for later rails version.

这篇关于为什么我在Rails中两次收到JQuery警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆