Rails 中的 Post 缺少参数?

Missing Params on Post in Rails?

我目前正在 Rails 上学习 Ruby,我们正在制作一个博客应用程序来了解 crud 操作等,我被我的控制器中的这个创建方法困住了不像在课程中那样工作。我在这个控制器中的创建方法有问题:

class ArticlesController < ApplicationController
    def show
        @article = Article.find(params[:id])
    end
    def index
        @articles = Article.all
    end
    def new

    end
    def create
        @article = Article.new(params.require(:article).permit(:title, :description))
        @article.save
        redirect_to @article
    end

end

我在尝试创建文章时遇到此错误:

ActionController::ParameterMissing in ArticlesController#create
param is missing or the value is empty: article

它似乎在创建方法的第一行挂了,但我不确定为什么它不认为有一篇文章......这是我的新文章视图以及进一步参考:

<h1>Create a new Article</h1>
<%= form_with scope: @article, url: articles_path, local: true do |f| %>
    <p>
        <%= f.label :title %><br/>
        <%= f.text_field :title %>
    </p>
    <p>
        <%= f.label :description %><br/>
        <%= f.text_area :description %>
    </p>
    <p>
        <%= f.submit %>
    </p>

<% end %>

检查您的参数是否在散列下,关键文章如下 -

{"article"=>{参数}}

同时在新操作中启动 Article 对象。

您可以像这样重新定义参数以允许:

在控制器新方法中创建对象

@article = Article.new

并在表格HTML中增加一个选项使用方法:"post"