开发者

Best way to add comments in erb

How do we add comments in erb files, if we do not want them to be generated into t开发者_开发百科he html content?


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.


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

/ comment here.... /

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜