1.11.1. Using Variables with ERb
You trigger ERb using embeddings, such as <% %>, <% -%>, and <%= %>. The <%= %> tag set is used when you want output. Consider the following loop for names:
<b>Names of all the people</b> <% for person in @people %> Name: <%= person.name %><br/> <% end %>
The loop is set up in regular embedding tags <% %>, and the name is written using the output embedding tag <%= %>. This is not just a usage suggestion. Regular output functions like print or puts won’t work with ERb templates. So, this would be wrong:
Hi, Mr. <% puts "Toad" %>
If you absolutely must write from within a function, you can use the TextHelper concat.
<%- and -%> suppress leading and trailing whitespace, including the trailing newline, and can be used interchangeably with <% and %>.
1.11.2. Layouts and Templates
One of the great benefits of using the Rails framework is the ability to use layouts. A layout defines the surroundings of an HTML page. It’s the place to define the common look and feel of your final output. Layout files ...