Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to add comments in erb

Use the <%# %> sequence, e.g.

<%# This is a great comment! %>

For Record

<%# This is a great comment! %>

<%#= This is a great comment! %>

For block comments:

<% if false %>
    code to be commented out...
<% end %> 

I have a Windows setup, and this <%-# %> sequence is the only one that works for me:

Example:

<%-# This is a sample comment! %>

In my text editor, i run command + / (sublime-text shortcut). It will be like this.

<%
=begin%>
    Here is the comment 
<%
=end%>

It doesn't look simply, but it works.


Since .erb is by definition "embedded ruby", you can embed every ruby code between: <%= and the other: %>, typically all written in one line. In addition, ruby one-line comments start always with #, so the <%=# Comment %> style matches perfectly with both pure-ruby and erb styles for one-line comments.