2017-08-10 25 views
0

我得到一個錯誤,指出:雲9紅寶石,同時使文章

https://i.stack.imgur.com/7mw12.png(這是錯誤的圖像)

new.html.erb

<h1> Create an article </h1> 
<%= form_for @article do |f| %> 
<p> 
<%= f.label :title %> 
<%=f.text_field :title %> 
</p> 
<% end %> 

articles_controller.rb

class ArticlesController < ApplicationController  

def new 
@article = Article.new 

end 

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' 
root 'pages#home' 
get 'about', to: 'pages#about' 
resources :articles 

我不知道如何使文章的模型,如果我沒有我不知道要放什麼東西在那裏...顯示,如果你告訴我如何[在這裏輸入的形象描述]我將不勝感激[1]

+0

'類文章

回答

0

我想你還沒有在模型文件夾中創建Article模型。因此它不能創建一個新的對象。 在你的模型文件夾此創建一個文件:

class Article < ApplicationRecord 

end 

,然後嘗試在第創建。新的命令

Article.new 
+0

所以我必須在我的模型文件夾中創建articles.rb文件? –

+0

我嘗試了我所理解的答案: class Article

+0

yes,但型號名稱總是單數,控制器名稱總是複數,在您的案例中,型號名稱爲'article.rb '和控制器名稱是'articles_controller'。 –