Rails: ActionView::Template::Error (undefined method `name' for nil:NilClass): app/views/users/show.html.erb:3
A view called a method on nil (or an undefined helper), so rendering failed — the error is wrapped in ActionView::Template::Error.
ActionView::Template::Error (undefined method `name' for nil:NilClass)ActionView::Template::Error (undefined local variable or method `current_user' for #<ActionView::Base)ActionView::Template::Error (undefined method `each' for nil:NilClass)ActionView::Template::Error: undefined method for nilActionView::Template::Error (undefined method `x' for Meaning
Read the line number in the view. Typical: @user not set in the controller action, a nil association (@post.author.name), or a missing helper/partial local. Use safe navigation (@post.author&.name), set instance variables in the controller, and pass locals to partials.
Common causes
- Instance variable not assigned in the controller
- nil association in the view
- Partial rendered without required locals
- Helper not available (namespaced/engine)
- Typo in method name
⚡ Quick fix
- Set
@user = User.find(params[:id])in the action - Use
&.ortryin views - Pass locals:
render partial: "card", locals: { user: @user }
Detailed fix by platform
Rails
bin/rails runner 'p Post.first&.author'
How to diagnose
- Line — View line?
- Variable — Assigned?
- Association — nil?
🔧 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
- ActionController::UrlGenerationError: No route matches {action...} missing required keys Rails: ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"users", :id=>nil}, missing required keys: [:id]
- ActionView::MissingTemplate: Missing template Rails: ActionView::MissingTemplate (Missing template users/show, application/show with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]})
- ActiveRecord::AssociationTypeMismatch Rails: ActiveRecord::AssociationTypeMismatch: User(#1234) expected, got "42" which is an instance of String(#5678)
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)
- CORS blocked in Rails API (rack-cors) Browser: Access to fetch at 'http://localhost:3000/api/items' from origin 'http://localhost:5173' has been blocked by CORS policy — Rails
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