I read the solutions to the problem on the following posts, but I couldn't apply them to my case:
- Rails, uninitialized constant Getting Started with Rails
- Routing Error uninitialized constant ArticleController
I am working on a test blog and I wanted to create a page for new articles called 'new.html.erb'. Here is it's code:
<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 %>
I also created a controller called 'articles.controller.rb':
class ArticlesController < ApplicationController
def new
@article = Article.new
end
end
I added the following line in the 'routes.rb'
resources :articles
When I try to access /articles/new in my rails app, it shows:
uninitialized constant ArticlesController
'$ rake routes' gives me the following output:
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
Here is my app on Github.