运行 云 9 中的应用程序时出现云 9 错误
I have a cloud 9 error while running the app in cloud 9
当我 运行 我的应用程序出现此错误
:
(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 %>
我的文章控制器文件:
class 文章控制器 < 应用程序控制器
def new
@article = Article.new
end
end
我的 article.rb 文件:
class Article
end
我的 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'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
如果 @article
不响应 model_name
以及 Rails 用于确定和生成 URL 的其他几种方法,则不能使用 form_for @article
。
鉴于您的问题带有 ruby-on-rails
标记,我猜您想将文章存储在数据库中。 ActiveRecord::Base
提供了这个方法。只是继承它。变化
class Article
end
到
class Article < ActiveRecord::Base
end
注意:只有当您的数据库中有一个名为 articles
的 table 时才有效。
当我 运行 我的应用程序出现此错误 :
(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 %>
我的文章控制器文件: class 文章控制器 < 应用程序控制器
def new
@article = Article.new
end
end
我的 article.rb 文件:
class Article
end
我的 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'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
如果 @article
不响应 model_name
以及 Rails 用于确定和生成 URL 的其他几种方法,则不能使用 form_for @article
。
鉴于您的问题带有 ruby-on-rails
标记,我猜您想将文章存储在数据库中。 ActiveRecord::Base
提供了这个方法。只是继承它。变化
class Article
end
到
class Article < ActiveRecord::Base
end
注意:只有当您的数据库中有一个名为 articles
的 table 时才有效。