Rendering ViewComponents can get verbose, especially for components that are used frequently:
<%= render Components::Icon.new(name: :check, text: "Done") %>
For frequently used components, consider adding a Rails helper in app/helpers/components_helper.rb:
module ComponentsHelper
def icon(...)
render Components::Icon.new(...)
end
end
Now your views can simply say:
<%= icon(name: :check, text: "Done") %>
The helper forwards all arguments to the component's constructor. Defaults and other configuration remain in the component constructor, so the helper needs no maintenance when its arguments change.
This works best for commonly used components. For rarely used components, maintaining an additional helper may not be worth it.
Generating helpers in bulk
If you have many components, you can generate helper methods instead of maintaining each one manually.
Two implementations to draw inspiration from:
- GOV.UK Components Show archive.org snapshot — explicitly maps helper names to components.
-
AbstractBrain: Using Rails helpers for rendering ViewComponents
Show archive.org snapshot
— automatically generates
x_-prefixed helpers (e.g.x_icon) for components found inapp/components. The prefix avoids name collisions with existing helpers.
Posted by Henning Koch to makandra dev (2026-11-03 10:47)