Skip to content

Linter Rule: Do not call render without rendering the result

Rule: actionview-no-silent-render

Description

Require that all render calls in ERB appear inside output tags (<%= ... %>), not control tags (<% ... %>). Otherwise, the call is evaluated but its result is silently discarded.

Rationale

Rails' render method returns HTML-safe strings meant to be included in the final response. If it's placed inside a non-output ERB tag (<% render(...) %>), the result is silently ignored. This is almost always a mistake and leads to confusion.

This rule catches these silent rendering issues and enforces that render is only used when its result is actually rendered.

Examples

✅ Good

erb
<%= render "shared/error" %>
erb
<%= render partial: "comment", collection: @comments %>
The partial `comment` is looked up relative to the directory of the template rendering it. Moving this template changes which file that resolves to, and renaming the partial means hunting for callers that never spell its full name. Write the full path from the view root so it resolves to the same file from any template, and a search for that path finds every caller. (actionview-prefer-qualified-partial-path)
erb
<%= render @product %>
Rails derives the partial from `to_partial_path` on `@product` when the template renders, so the template this renders is not named in this `<%= render %>` call. Name it explicitly, with `object:` for a single record or `collection:` for many, and Herb can take you to it, check the locals you pass against its strict locals, and help you rename them. (actionview-no-implicit-partial)

Escaped ERB tags (<%% and <%%=) are ignored. They render as the literal text <%/<%= rather than being executed, so generator and scaffold templates that emit render calls into the file they generate are not flagged:

erb
<%% cache [menu, @page] do %>
  <ul class="nav">
    <%%= render partial: menu.to_partial_path, collection: menu.children %>
  </ul>
<%% end %>

🚫 Bad

erb
<% render "shared/error" %>
Avoid using `<% %>` with `render`. Use `<%= %>` to ensure the rendered content is output. (actionview-no-silent-render)
Avoid using `<% %>` with `render`. Use `<%= %>` to ensure the helper's output is rendered. (actionview-no-silent-helper)
erb
<% render partial: "comment", collection: @comments %>
Avoid using `<% %>` with `render`. Use `<%= %>` to ensure the rendered content is output. (actionview-no-silent-render)
Avoid using `<% %>` with `render`. Use `<%= %>` to ensure the helper's output is rendered. (actionview-no-silent-helper)
erb
<% render @product %>
Avoid using `<% %>` with `render`. Use `<%= %>` to ensure the rendered content is output. (actionview-no-silent-render)
Avoid using `<% %>` with `render`. Use `<%= %>` to ensure the helper's output is rendered. (actionview-no-silent-helper)

References

-

Released under the MIT License.