Ruby Error
NameError
NameError is raised when Ruby encounters a name (variable, constant, or method) that it doesn't recognize. This is different from NoMethodError which specifically involves methods on objects.
Common causes
- Using a variable before it is defined
- Typo in variable or constant name
- Referencing a constant from wrong namespace
- Missing require for a class/module
- Variable defined in different scope
How to fix it
- Check for typos in variable/constant names
- Ensure variables are defined before use
- Use fully qualified constant names: Module::Class
- Add require statements for external dependencies
- Check variable scope (local, instance, class)
Example
NameError example
# Error example
puts user_name # => NameError: undefined local variable or method 'user_name'
# Fix by defining the variable first
user_name = "Alice"
puts user_name # => "Alice"
# Constant example
MyApp::User # => NameError if MyApp module not defined Track NameError with Checkend
Checkend automatically captures NameError errors in your Ruby application with full context:
- Complete backtrace with syntax highlighting
- Request context (URL, params, headers)
- Automatic grouping of similar errors
- Instant notifications when errors occur
Related errors
Stop debugging in production
Get full error context and fix issues faster with self-hosted error tracking.