Best way to add comments in erb
Ruby on-RailsRubyCommentsErbBlock CommentsRuby 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.... /