2016-11-07 145 views
0

我讀了解決問題的方案下列職位,但我不能將其應用到我的情況:Rails的路由錯誤 - 未初始化的常量ArticlesController

我正在測試博客,我想爲新文章創建一個名爲'new.html.erb'的頁面。下面是它的代碼:

<h1 align="center">Create an article</h1> 
<% end %> 
<%= form_for @article do |f| %> 
<p> 
<%= f.label :title %><br/> 
<%= f.text_field :title %> 
</p> 
<p> 
<%= f.label :description %><br/> 
<%= f.text_area :description %> 
</p> 
<p> 
<%= f.submit %> 
</p> 
<% end %> 

我還創建了一個名爲 'articles.controller.rb' 控制器:

class ArticlesController < ApplicationController 
    def new 
    @article = Article.new 
    end 
end 

我加了下面一行 'routes.rb中'

resources :articles 

當我嘗試訪問我的Rails應用中的/ articles/new時,它顯示:

未初始化不斷ArticlesController

'$耙路線' 給了我下面的輸出:

 Prefix Verb URI Pattern     Controller#Action 
     root GET /       pages#home 
pages_about GET /pages/about(.:format)  pages#about 
    articles GET /articles(.:format)   articles#index 
      POST /articles(.:format)   articles#create 
new_article GET /articles/new(.:format)  articles#new 
edit_article GET /articles/:id/edit(.:format) articles#edit 
    article GET /articles/:id(.:format)  articles#show 
      PATCH /articles/:id(.:format)  articles#update 
      PUT /articles/:id(.:format)  articles#update 
      DELETE /articles/:id(.:format)  articles#destroy 

這裏是my app on Github

回答

4

控制器

articles.controller.rb重命名爲articles_controller.rb

你的控制器名稱必須強調_分離。

+0

工作。非常感謝你。 – Nikl

1

您的控制器名稱錯誤。

應該articles_controller.rb,而不是articles.controller.rb

相關問題