我读了解决问题的方案下列职位,但我不能将其应用到我的情况:Rails的路由错误 - 未初始化的常量ArticlesController
- Rails, uninitialized constant Getting Started with Rails
- Routing Error uninitialized constant ArticleController
我正在测试博客,我想为新文章创建一个名为'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。
工作。非常感谢你。 – Nikl