roc*_*ter 3 ruby ruby-on-rails
我是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 <ApplicationController def索引@articles = Article.all结束
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
Run Code Online (Sandbox Code Playgroud)
错误警报所针对的行是params.require(:articles).permit(:title, :text)
我真的不知道错误可能在哪里,因为2分钟前一切正常。
谢谢您的帮助
您正在尝试通过edit方法更新文章。因此,当您导航到“ articles / 2 / edit /”时,它将尝试更新文章2。但是您没有传递任何参数。
我认为您可能想要的是:
def edit
@article = Article.find(params[:id])
end
def update
@article = Article.find(params[:id])
if @article.update(article_params)
redirect_to @article
else
render 'edit'
end
end
Run Code Online (Sandbox Code Playgroud)