2017-08-13 83 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

我想從用戶界面的文章將這仍然工作 –