Subscribe

Ruby 1.8.7 and ERB gotcha

No comments
Dec
8

While pairing with Bo on a new project, we were stumped with an odd issue with random HTML going missing.

It turns out <% # comment %> is not the same as <%# comment %>. Using <%# comment %> also comments all HTML until the next %> on another line after the initial comment.

So:

<% # comment %>
foo
<%= 'hello' %>
bar

Will print

hello
bar

but

<%# comment %>
foo
<%= 'hello' %>
bar

will print the intended result of

foo
hello
bar

Solution: Find and replace all instances of <% # with <%#.