O'Reilly logo

Text Processing with Ruby by Rob Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing Templates

To use ERB, we need to learn two things. First, we need to learn how to write the content of our ERB templates and how to use flow control, conditionals, and other Ruby constructs within them. And second, we need to learn how to actually execute these templates from within our Ruby code, including how to pass data into them.

ERB files are, in essence, plain text files. You don’t need to use any special invocations or formatting; any plain text file is, by definition, a valid ERB file. If we had a file containing the following text:

 
Hello, world

it would, when compiled as ERB, produce the output Hello, world. This is the key advantage of using a templating language like ERB: boilerplate content—such as the address in our ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required