Open
Description
Rule: erb-no-unused-tag-helpers
Description
Disallow calling ActionView tag helpers (like tag.div
, content_tag
, link_to
, etc.) without output. These helpers return HTML-safe strings but do not produce any visible effect unless rendered to the template via <%= %>
.
Using them inside control tags (<% %>
) silently discards the output, which is likely a mistake.
Rationale
Rails' view helpers such as tag.div
, content_tag
, and link_to
return HTML elements as strings. If these are used inside <% ... %>
, their return value is computed but never rendered, making them effectively useless.
This often happens due to typos or misunderstanding and leads to invisible bugs where expected output is simply missing.
Examples
✅ Good
<%= tag.div "Hello", class: "greeting" %>
<%= content_tag :section, "Welcome", id: "welcome" %>
<%= link_to "Click here", root_path %>
🚫 Bad
<% tag.div "Hello", class: "greeting" %>
<% content_tag :section, "Welcome", id: "welcome" %>
<% link_to "Click here", root_path %>
References
-