# Ruby: NameError: uninitialized constant UsersController::User (Did you mean? Users)

**Code:** `NameError: uninitialized constant` · **Category:** Ruby / Rails · **Seen on:** Ruby

Ruby (or Rails autoloading) couldn't find a class or module with that name in the current scope.

## 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

1. Check the constant's file/class name match
2. `bin/rails zeitwerk:check`
3. Use `::User` for top-level constants inside namespaces; add `require` for non-Rails code

## Detailed fix by platform

### Rails

1. `bin/rails zeitwerk:check && bin/rails runner 'p User'`

## How to diagnose

1. **Name** — Spelling/case?
2. **File** — Matches class?
3. **Namespace** — Lookup scope?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/ruby/nameerror-uninitialized-constant)
