Ruby: NameError: uninitialized constant UsersController::User (Did you mean? Users)
Ruby (or Rails autoloading) couldn't find a class or module with that name in the current scope.
NameError: uninitialized constant UsersController::Useruninitialized constant Foo::BarNameError: uninitialized constant Useruninitialized constant ActiveRecord::Base (Rails not loaded)NameError (uninitialized constant) Meaning
Causes: a typo, a missing require, a file/class name mismatch (Zeitwerk expects user_profile.rb → UserProfile), a namespace problem (UsersController::User means lookup inside the controller), or a gem not required. In Rails run bin/rails zeitwerk:check.
Common causes
- Typo or wrong capitalisation
- File name doesn't match the constant (autoload)
- Missing
require/gem not loaded - Constant looked up inside the wrong namespace (use
::User) - Class defined in a file not autoloaded (lib/ not in autoload paths)
⚡ Quick fix
- Check the constant's file/class name match
bin/rails zeitwerk:check- Use
::Userfor top-level constants inside namespaces; addrequirefor non-Rails code
Detailed fix by platform
Rails
bin/rails zeitwerk:check && bin/rails runner 'p User'
How to diagnose
- Name — Spelling/case?
- File — Matches class?
- Namespace — Lookup scope?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- ActiveRecord::AssociationTypeMismatch Rails: ActiveRecord::AssociationTypeMismatch: User(#1234) expected, got "42" which is an instance of String(#5678)
- ActiveRecord::ConnectionNotEstablished Rails: ActiveRecord::ConnectionNotEstablished: No connection pool for 'ActiveRecord::Base' found
- ActiveRecord::Deadlocked: PG::TRDeadlockDetected Rails: ActiveRecord::Deadlocked: PG::TRDeadlockDetected: ERROR: deadlock detected
Most viewed in Ruby / Rails
- ActiveRecord::PendingMigrationError Rails: ActiveRecord::PendingMigrationError — Migrations are pending. To resolve this issue, run: bin/rails db:migrate
- ActionController::InvalidAuthenticityToken Rails: ActionController::InvalidAuthenticityToken (Can't verify CSRF token authenticity)
- Bundler could not find compatible versions for gem Bundler: Bundler could not find compatible versions for gem "activesupport": In Gemfile: rails (= 7.1.0) depends on activesupport (= 7.1.0)
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026