Best way to add comments in erb

2019-01-12 16:56发布

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

5条回答
该账号已被封号
2楼-- · 2019-01-12 17:11

For block comments:

<% if false %>
    code to be commented out...
<% end %> 
查看更多
贪生不怕死
3楼-- · 2019-01-12 17:15

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

<%# This is a great comment! %>
查看更多
贪生不怕死
4楼-- · 2019-01-12 17:16

For Record

<%# This is a great comment! %>

<%#= This is a great comment! %>
查看更多
不美不萌又怎样
5楼-- · 2019-01-12 17:20

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.

查看更多
贼婆χ
6楼-- · 2019-01-12 17:30

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

Example:

<%-# This is a sample comment! %>
查看更多
登录 后发表回答