Best way to add comments in erb

Ruby on-RailsRubyCommentsErbBlock Comments

Ruby on-Rails Problem Overview


How do we add comments in erb files, if we do not want them to be generated into the html content?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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

<%# This is a great comment! %>

Solution 2 - Ruby on-Rails

For Record

<%# This is a great comment! %>

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

Solution 3 - Ruby on-Rails

For block comments:

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

Solution 4 - Ruby on-Rails

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

Example:

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

Solution 5 - Ruby on-Rails

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.

Solution 6 - Ruby on-Rails

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.

Solution 7 - Ruby on-Rails

I doesn't work in the Controllers files, I had to put it between slashes

/ comment here.... /

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKalyan MadduView Question on Stackoverflow
Solution 1 - Ruby on-RailsJohn DouthatView Answer on Stackoverflow
Solution 2 - Ruby on-RailsSalilView Answer on Stackoverflow
Solution 3 - Ruby on-RailsTimView Answer on Stackoverflow
Solution 4 - Ruby on-RailsEdward CastañoView Answer on Stackoverflow
Solution 5 - Ruby on-RailsMiftah MizwarView Answer on Stackoverflow
Solution 6 - Ruby on-RailsMaaaaaaarcoView Answer on Stackoverflow
Solution 7 - Ruby on-RailsArezkiView Answer on Stackoverflow