gpt4 book ai didi

ruby-on-rails - 返回 : Delete action only reloading page

转载 作者:数据小太阳 更新时间:2023-10-29 08:11:18 25 4
gpt4 key购买 nike

我相信我已经完全遵循了教程,但是当我单击“Trash It”链接时,页面会重新加载到相同的 @doc 页面,没有任何变化。

看看代码,让我知道需要更改什么。

DELETE 是 docs#destroyrake routes 下列出的动词。

非常感谢您的帮助!

show.html.haml:

%h1= @doc.title
%p= @doc.content

= link_to "All Docs", docs_path
= link_to "Fix Docs", edit_doc_path(@doc)
= link_to "Trash It", doc_path(@doc), method: :delete, data: { confirm: "Are you Sure?" }

docs_controller.rb:

class DocsController < ApplicationController
before_action :find_doc, only: [:show, :edit, :update, :destroy]

def index
@docs = Doc.all.order("created_at DESC")
end

def show
end

def new
@doc = Doc.new
end

def create
@doc = Doc.new(doc_params)

if @doc.save
redirect_to @doc
else
render 'new'
end
end

def edit
end

def update
if @doc.update(doc_params)
redirect_to @doc
else
render 'edit'
end
end

def destroy
@doc.destroy
redirect_to docs_path
end

private

def find_doc
@doc = Doc.find(params[:id])
end

def doc_params
params.require(:doc).permit(:title, :content)
end
end



Rails.application.routes.draw do
get 'welcome/index'

root 'welcome#index'

resources :docs
end

最佳答案

确保 gem 'jquery-rails' 在 gemfile 中并且 jquery_ujs 包含在 app/assets/javascripts/application.js 文件中

//= require jquery
//= require jquery_ujs

我相信你的问题是相似的this question .

关于ruby-on-rails - 返回 : Delete action only reloading page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40248876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com