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:
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.
Any existing second level directories called app/*/concerns in the application and engines.
The directory test/mailers/previews.
Rails: uninitialized constant Controller
As far as I know just namespace
s and scope
s 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
Rubygems, Bundler and Rvm Confusion
What's the Best Way to Unit Test Protected & Private Methods in Ruby
Replace Words in a String - Ruby
Ruby Class Inheritance: What Is '<<' (Double Less Than)
Can You Get Db Username, Pw, Database Name in Rails
How to Get Ruby to Print a Full Backtrace Instead of a Truncated One
How to Round a Time Down to the Nearest 15 Minutes in Ruby
How to Implement Cookie Support in Ruby Net/Http
How to Remove the String "\N" from Within a Ruby String
Directly Accessing an Instance Variable VS. Using an Accessor Method
Insecure World Writable Dir /Users/Username in Path, Mode 040777 When Running Ruby Commands
Ruby Metaprogramming: Dynamic Instance Variable Names
How to Pass Arguments to Define_Method
How to Know If Today's Date Is in a Date Range
Combine Array of Array into All Possible Combinations, Forward Only, in Ruby
Homebrew Installation on MAC Os X Failed to Connect to Raw.Githubusercontent.Com Port 443