Uninitialized Constant "Controller Name"

Uninitialized constant Controller Name

It should be SchedulesController, not Users::ScheduleController. Controllers should only be namespaced when the route is namespaced with namespace. Controller names should also always be plural.

What you're creating is a nested resource, not a namespaced one.

Uninitialized constant controller name

The Controller name has to be pluralized.

nicknames_controller.rb

class NicknamesController < ApplicationController

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.

Rails: uninitialized constant Controller

As far as I know just namespaces and scopes require a nested module.

NameError: uninitialized constant ControllerName after adding routing namespace

When you have a controller route namespace like

api/v1/stores

then Rails expects the controller to be named

Api::V1::StoresController 

and to be located in a file named

app/controllers/api/v1/stores_controller.rb

Uninitialized constant error in Rails controller

Your app/commands folder doesn't seem to be loaded into Rails at boot.

You need to include your app/commands in your autoload paths for this to work or require the file manually in your controller.

See: https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoload-paths

Uninitialized constant in controller Rails


uninitialized constant RostersController::Roster

You should have a model file with the name roster.rb in app/models

#roster.rb

class Roster < ActiveRecord::Base
end

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



Related Topics



Leave a reply



Submit