ERB Cribsheet

Intro to ERB

  • “Embedded Ruby”
  • One of a class of ‘template languages’
  • There are many
  • They do a simple job (used to be called “mail merge”)
What it does
  • Erb file without any `` blocks remains unchanged
  • <% %> must contain legal ruby code!
  • The code between the angle brackets is evaluated.
  • *And only in the case of <%= %> it’s inserted into the resulting text
Example
 1<% %w(Jones Hickey Salas Madeiras).each do |name| %>
 2  ----
 3  Dear Mr. <%= name %>,
 4  I am writing to let you know that I have moved, and my new
 5  address is 1 Main Street, San Fransisco, CA. Please make
 6  a note of it.
 7
 8  Sincerely,
 9
10  Tom
11  -----
12<% end %>