ActionView::Template::Error in CI
A template raised while rendering, and ActionView wrapped it in Template::Error with the offending template and line. The wrapped exception underneath is what you actually need to fix.
What this error means
A request, system, or view spec fails with ActionView::Template::Error naming a template and line, followed by the underlying error. Common in CI when data the view assumes is absent or a helper/asset is missing.
ActionView::Template::Error:
undefined method `name' for nil:NilClass
# ./app/views/orders/show.html.erb:4
<h1><%= @order.customer.name %></h1>Common causes
Missing data in the view
An instance variable or association the template uses is nil in the test setup, so a method call inside the view raises.
Missing partial or helper
A render references a partial that does not exist, or a helper method not loaded in the test context.
Asset/path helper failure
asset_path or image_tag points at an asset the test environment did not build, raising inside the template.
How to fix it
Fix the wrapped error
- Read the underlying exception under the Template::Error wrapper and the cited template line.
- Provide the missing data in setup, or guard nil in the view.
- Add the missing partial/helper, or precompile the referenced asset for tests.
Guard nil in the template
<h1><%= @order.customer&.name %></h1>How to prevent it
- Set up complete data for view/request specs.
- Use safe navigation for optional associations in templates.
- Build or stub assets the view references in the test env.