Routing Error - Uninitialized Constant

Routing error - uninitialized constant

Rails requires the file name to match the class name. Therefore you should rename app/controllers/authentication_controller.rb to app/controllers/authentications_controller.rb.

Routing Error uninitialized constant ArticleController

Controller names are plural

class ArticlesController < ApplicationController #notice, it is Articles

This means, in your config/routs.rb, you need to have a route that maps to articles (plural).

this surely means, in your config/routes.rb, you have a resources :article.
and so the route is being mapped to a controller named Article, which you don't have it, and which is incorrect anyway. this is why you are getting Routing Error uninitialized constant ArticleController because it can't find a controller named Article (singular)

It should be resources :articles. that way, it is going to look for a controller name Articles

bottom line: controller names are pluralized. so check your namings.

Rails Routing Error: Uninitialized Constant with Nested Resources

The key is what rails routes is telling you:

user_task_path  GET /users/:user_id/tasks/:id(.:format)  tasks#show

That last section tells you that it’s looking for the show method in the tasks controller – that is, TasksController at the top level of the controller hierarchy.

So rather than placing TasksController at app/controllers/users/tasks_controller.rb, you need to place it at app/controllers/tasks_controller.rb.

The “nesting” of the controller is handled by the params object containing both :user_id and :id when TasksController#show is called.

Routing Error uninitialized constant controller

If your file is located inside the app/controllers folder, then it is probably a file name issue. Your file should have the name clasa9_controller.rb.

If not, then you should load the file by creating an initializer or by adding an autoload_path inside config/development.rb

Rails loads by default:

  1. All subdirectories of app in the application and engines present at boot time. For example, app/controllers. They do not need to be the default ones, any custom directories like app/workers belong automatically to autoload_paths.

  2. Any existing second level directories called app/*/concerns in the application and engines.

  3. The directory test/mailers/previews.

Getting Uninitialized constant routing error when loading a view

One of the great things about Rails is its preference for convention over configuration. However, for this to really benefit you, you need to stick to doing things “The Rails Way” rather than your own way, wherever possible.

In this case, start by getting rid of your custom get route, and just use resources :cars.

From the command line, run rake routes (you might be able to run rails routes on your rails version too) and see the routes that it has created for you.

Now, rename the method you added to your CarsController from hello to index.

Move your hello.html.erb file from app/views/layout to app/views/cars/index.html.erb.

Finally, start the rails server (rails start) and load the url http://localhost:3000/cars in your browser.

—-

Note that templates in app/views/layout have a special purpose. These are used to apply a general template to your views. Look up the use of layout within a controller for more details

ActionController::RoutingError (uninitialized constant Members) in Production Only

After much research, this error can be caused for a host of reasons. I will post the answer that fixed my particular issue that caused this error, in case someone in the future has the same issue.

Now, on to fix the last problems before launching my site tomorrow. Thank you all for your help in tracking down the issue.

Answer:

If you look in my question, the sessions_controller.rb was nested under 'Members' not 'members'. As @max pointed out in his clarifying comments, the file system on my local machine is case-insensitive, where as in production it is case sensitive. So, that is why "Members" was not initialized.

Routing Error: uninitialized constant

According to http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing you should use scope instead of namespace.

If you want to route /admin/posts to PostsController (without the Admin:: module prefix), you could use:

scope "/admin" do
resources :posts, :comments
end


Related Topics



Leave a reply



Submit