16.1. ERB Replacements
The stated design rationale for using ERB as the template language for Rails views is to keep the programming language as consistent as possible — Ruby in the controller, Ruby in the model, and Ruby in the view. There's an admirable consistency to that structure, but nevertheless, Rails has been dogged by complaints about the ERB structure from the very beginning. To some extent, that's because it's a hard problem — I'm not aware of any web tool whose view language is considered completely satisfying. The paradigm of mixing HTML with markup has been around since the first web frameworks, though, and it's certainly a comfortable one for many web developers.
However, there's also a feeling that the mixing of HTML and Ruby code is not always the clearest or most satisfying way of describing a view. For my part, I find the issue of indenting an ERB file properly to be annoying. A table with a header row and then rows within a loop, for instance, winds up with the table rows at two different levels of indentation. (I'm also not happy with the way the ERB delimiters mess up the indentation.) On some level, that's just an aesthetic gripe, but I also feel that it suggests that the structure of the HTML/markup file is wrong, or at least not optimal.
In this section, you'll look at a few replacements that have been developed for ERB views. Design goals of these tools include the desire to create a simpler, more flexible template language, as well as to add a more ...
Get Professional Ruby on Rails™ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.