How do we add comments in erb files, if we do not want them to be generated into the html content?
Use the <%# %>
sequence, e.g.
<%# This is a great comment! %>
<%
and #
–
Cartomancy <%
and #
–
Cartomancy For Record
<%# This is a great comment! %>
<%#= This is a great comment! %>
<%=
-> <%#=
example is useful. It doesn't require a special case and isn't documented. It works and is the easiest, though! (Beats having to guess whether there was an =
when uncommenting it.) –
Philharmonic <%= ... %>
by turning it into a comment. –
Selfaddressed For block comments:
<% if false %>
code to be commented out...
<% end %>
<%# %>
tag. –
Emelda 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.
command
in this context? –
Feltner Since .erb is "embedded ruby" by definition, you can embed any 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.
<html> <body> <form method="POST" action="www.some-url.com"> <input id="data" name="data" value="<%=# "String" %>"> <input type="submit" value="Send"> </form> </body> </html>
throws an error –
Coaster value="<%=# 'String' %>"
–
Theda I doesn't work in the Controllers files, I had to put it between slashes
/ comment here.... /
In Embedded Ruby (ERB), which is commonly used in Ruby on Rails applications, you can add comments using the <%# ... %>
© 2022 - 2024 — McMap. All rights reserved.