Examples of Ruby ERB Syntax


<% %>

Executes the ruby code within the brackets. It’s for any Ruby code, but doesn’t output the results (e.g. if statements).

<%= %>

Prints something into erb file. It’s for outputting the results of Ruby code.

<% -%>

Avoids line break after expression. It suppresses leading and trailing whitespace.

<%# %>

Comments out code within brackets; not sent to client (as opposed to HTML comments).

Visit Ruby Doc for more infos about ERB.