2017-08-13 55 views
0

运行应用程序时,我跑我的应用程序我得到这个错误 :我有一个云端9错误,而在云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:/家庭/ ubuntu的/工作区/ 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 < ApplicationController的

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' 

回答

0

不能form_for @article如果@article使用并不model_name做出回应,会被Rails使用几个其他的方法来确定和生成URL。

鉴于你的问题被标记为ruby-on-rails我想你想要在数据库中存储文章。 ActiveRecord::Base提供了这种方法。只是从它继承。更改

class Article 
end 

class Article < ActiveRecord::Base 
end 

注:这仅适用如果有一个在你的数据库名为articles表。

+0

我得到一个错误,指出:#新 找不到表“文章”这是给我看我的文章控制器文件 的ActiveRecord :: StatementInvalid在ArticlesController:类ArticlesController

+0

错误消息'找不到表“articles''是相当具体。没有数据库表来存储您使用表单创建的文章。只需创建一个数据库迁移,添加所需的表和列并运行它。请参阅[关于迁移的Rails指南](http://edgeguides.rubyonrails.org/active_record_migrations.html)。 – spickermann

+0

我想从用户界面的文章将这仍然工作 –