Reputation: 2792
I'm trying to build a simple rails application however I get a routing error. Here is the controller:
class PostsController < ActionController::Base
def index
@var = "Rails is amazing"
end
end
Here is the routing:
get "/posts", to: "posts#index"
And the routing error is as following:
uninitialized constant PostsController
The url im accessing is this one:
http://localhost:3000/posts#
I understand that controllers should be pluralised in both the routing and in the name of the file. I am sorry for such a novice question
Upvotes: 1
Views: 38
Reputation: 5734
I believe, you have posts_controller.rb file in the controllers folder.In the posts_controller.rb
file add the following syntax
class PostsController < ApplicationController
end
In your routes file, try adding
resources :routes
In the terminal if you will type CONTROLLER=posts rake routes
, you ll get the following output
Prefix Verb URI Pattern Controller#Action
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
Upvotes: 1