Jos*_*osh 3 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?' }
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
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'
Run Code Online (Sandbox Code Playgroud)
application.js
//= require jquery
//= require jquery_ujs
//= require rails-ujs
//= require turbolinks
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
571 次 |
| 最近记录: |