文章中的 NoMethodError#new undefined method `model_name' for #<Article:0x000000035a3450>

NoMethodError in Articles#new undefined method `model_name' for #<Article:0x000000035a3450>

我在从 UI 创建文章时遇到问题。

我的任务是创建一个新页面,在页面上显示 "create an article" 并在文本字段中显示标题和描述以及提交按钮,当我按下提交按钮时,我输入的文章应该被保存,当我转到保存文章的页面,它们应该在那里。

错误日志:

这是我的 Cloud 9 代码

routes.rb:

Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

# You can have the root of your site routed with "root"
# root 'welcome#index'
resources :articles

root 'pages#home'
get 'about', to: 'pages#about'

文章管理员(articles_controller.rb):

class ArticlesController < ApplicationController
  def new
    @article = Article.new 
  end
end 

new.html.erb 在视图的文章文件夹中:

<h1>Create an article</h1>
<%= form_for @article do |f| %>
<% end %>

文章模型(article.rb):

class Article 

end

您的 Article 模型是 ActiveRecord::Base 的子类吗(ApplicationRecord 来自 Rails 5.x)?

class Article < ActiveRecord::Base

end