We previously looked at refactoring Rails views with ViewComponent templates. Each template requires a Ruby file and an ERb file. What if there was a way to get rid of the latter?
Since we already have a refactored example application,
we get to skip right to swopping out ViewComponent templates for
As per the docs, we add the Rux Rails gem to the development group of our Gemfile.
# Gemfile ... group :development do gem "rux-rails", "~> 1.0" end ...
PageHeaderComponent was defined across two files:
# app/components/page_header_component.rb class PageHeaderComponent < ApplicationComponent end
# app/components/page_header_component.html.erb <div class="pb-2 border-b"> <%= content %> </div>
We can get rid of the ERb template by adding a
template method to our
Thanks for reading!