【发布时间】:2017-08-13 23:07:49
【问题描述】:
当我运行我的应用程序时出现此错误 :
(NoMethodError in Articles#new
Showing /home/ubuntu/workspace/yappy/qaucky/app/views/articles/new.html.erb where line #3 raised:
undefined method `model_name' for #<Article:0x007ff8e20e4b50>
提取的源代码(第 3 行附近):
<h1>Create an article</h1>
<%= form_for @article do |f| %>
<% end %>
这是图片 (https://i.stack.imgur.com/kghdF.png)
Rails.root:/home/ubuntu/workspace/yappy/qaucky)
资源:文章
root 'pages#home'
get 'about', to: 'pages#about'
我的 new.html.erb 文件:
<h1>Create an article</h1>
<%= form_for @article do |f| %>
<% end %>
我的文章控制器文件:
类 ArticlesController 我的 article.rb 文件: 我的 routes.rb 文件:def new
@article = Article.new
end
end
class Article
end
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'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 cloud9-ide cloud9