我按照此tutorial構建了一個簡單的博主。無法在Rails控制器中執行刪除操作
但是,我無法執行本教程所示的刪除功能。是
給出的步驟如下:
讓我們來定義我們ArticlesController的銷燬方法,因此:
用途PARAMS [:ID]來查找數據庫中的文章
致電該物件的破損
重定向到藝術品icles索引頁
現在就自己做並測試它。
這是我的代碼:
class ArticlesController < ApplicationController
include ArticlesHelper
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id])
end
def new
@article = Article.new
end
def create
@article = Article.new(article_params)
@article.save
flash.notice = "Article '#{@article.title}' Created!"
redirect_to article_path(@article)
end
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to articles_path
end
end
show.html.erb
<h1><%= @article.title %></h1>
<p><%= @article.body %></p>
<%= link_to "<< Back to Articles List", articles_path %>
<%= link_to "delete", article_path(@article), method: :delete %>
article_helper.rb
module ArticlesHelper
def article_params
params.require(:article).permit(:title, :body)
end
end
我已經通過其他的解決方案瀏覽在線,但我不沒有看到我可能錯過的任何代碼。
就我而言,單擊刪除鏈接只會導致頁面刷新。
爲什麼'私人'?向上移動 –
謝謝,我正在關注github上的修改過的教程,我根據較新的教程更新了代碼,但它仍然無法正常工作。 – Carrein
最新的錯誤? – puneet18