ERB versus HAML

ERB

The ERB of html.erb is a system to interpret code in an html.erb file between <%= and %> as Ruby code and executed.  In HAML all you need to trigger the computer to read a line as Ruby code is an = (equal sign)

ERB: <%= Time.now %>

HAML: = Time.now

As you can see, HAML is cleaner. 

Fun HAML Tricks

For many types of embedded Ruby code, the = sign replaces the ERB <% = %>.  This apparently is if the code is intended for display.  E.g. = image_tag or = link_to. 

 

For if and else statements, the -sign replaces the ERB <%   %>.  This apparently is for code that is intended to be hidden.

| Back

Footerfull