Ruby on rails Ruby on rails错误:缺少参数或值为空
我似乎无法调试这个错误。下面是Ruby on rails教程: 错误来自我的控制器,下面是代码:Ruby on rails Ruby on rails错误:缺少参数或值为空,ruby-on-rails,ruby,Ruby On Rails,Ruby,我似乎无法调试这个错误。下面是Ruby on rails教程: 错误来自我的控制器,下面是代码: class ArticlesController < ApplicationController def index @articles = Article.all end def show @article = Article.find(params[:id]) end def new end def create @article
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id])
end
def new
end
def create
@article = Article.new(params.require(article_params))
@article.save
redirect_to @article
end
private
def article_params
params.require(:article).permit(:title, :text)
end
end
以下是我的观点,以备您需要:
<h1>New Article </h1>
<%= form_for :article, url: articles_path do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_field :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
新文章
应该是
@article = Article.new(article_params)
@article = Article.new(params.require[article_params])
由于您已经允许了
article_params
method中的属性,请注意您已经编写了
@article = Article.new(params.require(article_params))
然而它应该是
@article = Article.new(article_params)
@article = Article.new(params.require[article_params])
i、 e.[]而不是()围绕着文章参数。把这个@article=article.new article\u paramw放在这里,我是个白痴。我真不敢相信我没有看到这一点。我确实觉得这很有帮助,我不得不等待计时器,然后才能接受。