Skip to content

Linter Rule: Disallow silent ERB tags for Action View helpers

Rule: actionview-no-silent-helper

Description

Action View helpers like link_to, form_with, and content_tag must use output ERB tags (<%= %>) so their rendered HTML is included in the page. Using silent ERB tags (<% %>) discards the helper's output entirely.

Rationale

Action View helpers generate HTML that needs to be rendered into the template. When a helper is called with a silent ERB tag (<% %>), the return value is evaluated but silently discarded, meaning the generated HTML never appears in the output. This is almost always a mistake and can lead to confusing bugs where elements are missing from the page with no obvious cause. Using <%= %> ensures the helper's output is properly rendered.

Examples

✅ Good

erb
<%= link_to "Home", root_path %>
erb
<%= form_with model: @user do |f| %>
  <%= f.text_field :name %>
<% end %>
erb
<%= button_to "Delete", user_path(@user), method: :delete %>
erb
<%= content_tag :div, "Hello", class: "greeting" %>

A silent tag is fine when the helper's return value is used instead of being discarded, for example by an assignment, a capture, or another method call:

erb
<% link = link_to "Home", root_path %>

<%= link %>
erb
<% actions = capture { render "profiles/actions", user: user } %>

<% if actions.strip.present? %>
  <%= actions %>
<% end %>

🚫 Bad

erb
<% link_to "Home", root_path %>
Avoid unused expressions in silent ERB tags. `<% link_to "Home", root_path %>` is evaluated but its return value is discarded. Use `<%= link_to "Home", root_path %>` to output the value or remove the expression. (erb-no-unused-expressions)
Avoid using `<% %>` with `link_to`. Use `<%= %>` to ensure the helper's output is rendered. (actionview-no-silent-helper)
erb
<% form_with model: @user do |f| %>
  <%= f.text_field :name %>
<% end %>
erb
<% button_to "Delete", user_path(@user), method: :delete %>
Avoid unused expressions in silent ERB tags. `<% button_to "Delete", user_path(@user), method: :delete %>` is evaluated but its return value is discarded. Use `<%= button_to "Delete", user_path(@user), method: :delete %>` to output the value or remove the expression. (erb-no-unused-expressions)
Avoid using `<% %>` with `button_to`. Use `<%= %>` to ensure the helper's output is rendered. (actionview-no-silent-helper)
erb
<% content_tag :div, "Hello", class: "greeting" %>
Avoid unused expressions in silent ERB tags. `<% content_tag :div, "Hello", class: "greeting" %>` is evaluated but its return value is discarded. Use `<%= content_tag :div, "Hello", class: "greeting" %>` to output the value or remove the expression. (erb-no-unused-expressions)
Avoid using `<% %>` with `content_tag`. Use `<%= %>` to ensure the helper's output is rendered. (actionview-no-silent-helper)

References

Released under the MIT License.