# Rails: ActionView::Template::Error (undefined method `name' for nil:NilClass): app/views/users/show.html.erb:3

**Code:** `ActionView::Template::Error: undefined method for nil in view` · **Category:** Ruby / Rails · **Seen on:** Ruby

A view called a method on `nil` (or an undefined helper), so rendering failed — the error is wrapped in `ActionView::Template::Error`.

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

1. Set `@user = User.find(params[:id])` in the action
2. Use `&.` or `try` in views
3. Pass locals: `render partial: "card", locals: { user: @user }`

## Detailed fix by platform

### Rails

1. `bin/rails runner 'p Post.first&.author'`

## How to diagnose

1. **Line** — View line?
2. **Variable** — Assigned?
3. **Association** — nil?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/ruby/rails-actionview-template-error-undefined-method)
