Phlex for Rails Emails: Action Mailer Without ERB
Published on: 2025-07-08 14:20:45
Writing Ruby all day is fun, but writing Ruby in HTML is not. In the past months, I found switching from Ruby to ERB views and partials to be interrupting my flow and therefore increasingly annoying. Enter Phlex, which is a Ruby library that allows you to write HTML (components, views, layouts) in pure Ruby. After already completely ditching ERB for Phlex in Rails views for multiple applications, I wanted to see if I could do the same for Action Mailer. ERB be gone!
Why might this be interesting, besides just trying it out for the sake of it, and to see if it’s possible? I see these benefits:
No more ERB: Use Phlex all the way, even for mailers
Manage the HTML and text version of the email in one place
Use Phlex components for layouts and views
As for my part, I could gladly live without ERB in my Rails applications. After all, if it does not spark joy when you touch it, you should get rid of it.
Check out the repository for the full code. I hope you find this as exciting as I do
... Read full article.