HAML or ERB for Ruby on Rails development in 2021?
I’m often asked why I use HAML for my projects.
- easier to read than
- easier to write than
- wide adoption: some time ago I did a poll on r/rails to see it’s pupularity. Results:
Clearly, HAML is a modern and popular choice for web development with Ruby on Rails 6.
VERY useful websites that help converting bulk code from haml to erb, that I use on a daily basis:
2022 Update: Back 2
After years of using and advocating for
HAML, I’m switching back to
Why? Not because I like it more.
- Because it is more popular, thus lowering the entry barrier for people reading my code. (Stupid reason)
- Because in the new world of StimulusJS & Hotwire Turbo we now have to write a lot of
dom_ids, and I want to keep everything consistent. (Better reason)
- Because I had to get used to using it at work.
Althrough, haml-like logical nesting will forever be a must-have in my code. And if I had to draft an HTML page right away (without a framework), I would be able to do it faster and more elegantly in HAML. Haml is a viable way to writing beautiful HTML, that can be used way beyond the context of Ruby on Rails.