【发布时间】:2014-07-25 21:29:32
【问题描述】:
我正在从 Jumpstart 实验室 http://tutorials.jumpstartlab.com/projects/blogger.html 做关于创建博客应用程序的教程
当我删除文章时,我遇到了错误“ActiveRecord::RecordNotFound in ArticlesController#show Couldn't find Article with 'id”
错误发生在 artciles_controller.rb 的第 10 行,即 @article = Article.find(params[:id])
articles_controller.rb
class ArticlesController < ApplicationController
include ArticlesHelper
def index
@articles = Article.all
end
def edit
@article = Article.find(params[:id])
end
def show
@article = Article.find(params[:id])
@comment = Comment.new
@comment.article_id = @article.id
end
def new
@article = Article.new
end
def create
@article = Article.new(article_params)
@article.save
redirect_to article_path(@article)
end
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to article_path(@article)
end
def update
@article = Article.find(params[:id])
@article.update(article_params)
flash.notice = "Article '#{@article.title}' Updated!"
redirect_to article_path(@article)
end
end
show.html.erb
<h1><%= @article.title %></h1>
<p><%= @article.body %></p>
<h3>Comments (<%= @article.comments.size %>)</h3>
<%= render partial: 'arti`enter code here`cles/comment', collection: @article.comments %>
<%= link_to "edit", edit_article_path(@article) %>
<%= render partial: 'comments/form' %>
<%= link_to "<< Back to Articles List", articles_path %>
<%= link_to "delete", article_path(@article) ,
method: :delete ,
data: {confirm: "Really delete the article?"}%>
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 activerecord