【发布时间】:2016-11-07 10:35:53
【问题描述】:
我在以下帖子中阅读了问题的解决方案,但我无法将它们应用到我的案例中:
- 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
'$ rake routes' 给我以下输出:
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。
【问题讨论】:
标签: ruby-on-rails