Skip to Main Content
Professional Ruby on Rails™
book

Professional Ruby on Rails™

by Noel Rappin
February 2008
Intermediate to advanced content levelIntermediate to advanced
479 pages
14h
English
Wrox
Content preview from Professional Ruby on Rails™

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby on Rails® Bible

Ruby on Rails® Bible

Timothy Fisher
Rails 4 in Action

Rails 4 in Action

Yehuda Katz, Rebecca Skinner, Stephen Klabnik, Ryan Bigg

Publisher Resources

ISBN: 9780470223888Purchase book