【发布时间】:2014-12-26 15:15:02
【问题描述】:
我是 Rails 新手,我开始按照 rubyonrails.org 教程制作 Web 应用程序。
我的应用程序是一个包含文章的博客。我实现了创建和编辑功能,这些功能运行良好,但在尝试访问 http://localhost:3000/articles/2/edit 以编辑文章时突然出错。
错误是ActionController::ParameterMissing in ArticlesController#edit param is missing or the value is empty: articles
这是我的红宝石代码:
类 ArticlesController
def new
@article = Article.new
end
def edit
@article = Article.find(params[:id])
if @article.update(article_params)
redirect_to @article
else
render 'edit'
end
end
def show
@article = Article.find(params[:id])
end
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render 'new'
end
end
private
def article_params
params.require(:article).permit(:title, :text)
end
end
错误警报针对的行是params.require(:articles).permit(:title, :text)
我真的不知道错误在哪里,因为 2 分钟前一切正常...
感谢您的帮助
【问题讨论】:
-
确保您使用的是
:article而不是:articles。
标签: ruby-on-rails ruby