ArticlesController#show中的ActiveRecord :: RecordNotFound找不到没有ID的文章

我正在尝试向db提交一些数据,但是当我试图检索那些数据显示无法找到没有ID.ils 4.0.1的文章时。 我使用ruby 2.0.0和ra

def show @article=Article.find(params[:id]) 

结束

 the ** contain error. class ArticlesController < ApplicationController def new end def create @article = Article.new(article_params) redirect_to @article @article.save end def show @article=Article.find(params[:id]) end private def article_params params.require(:article).permit(:title, :full_name, :email, :phone_number, :message) end end 

文章/ show.html.erb

 

Title:

Full Name:

Email:

Phone Number:

Message:

文章/ new.html.erb

 

New Articles

在实际保存文章之前,您正在重定向。

这个:

 def create @article = Article.new(article_params) redirect_to @article @article.save end 

应该:

 def create @article = Article.new(article_params) @article.save redirect_to @article end 

如果你想添加一些error handling:

 def create @article = Article.new(article_params) if @article.save redirect_to @article else render :new end