2016-11-07 142 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

相关问题