Ruby-on-rails 在 erb 中添加评论的最佳方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2774841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:37:33  来源:igfitidea点击:

Best way to add comments in erb

ruby-on-railsrubyerb

提问by Kalyan Maddu

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

如果我们不希望将它们生成到 html 内容中,我们如何在 erb 文件中添加注释?

回答by John Douthat

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

使用<%# %>序列,例如

<%# This is a great comment! %>

回答by Salil

For Record

备案

<%# This is a great comment! %>

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

回答by Tim

For block comments:

对于块注释:

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

回答by Edward Casta?o

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

我有一个 Windows 设置,这个 <%-# %> 序列是唯一对我有用的序列:

Example:

例子:

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

回答by Maaaaaaarco

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.

由于 .erb 根据定义是“嵌入式 ruby​​”,您可以在:<%=和另一个:之间嵌入每个 ruby​​ 代码%>,通常都写在一行中。此外,ruby 单行注释总是以 开头#,因此该<%=# Comment %>样式与单行注释的纯 ruby​​ 和 erb 样式完美匹配。

回答by Arezki

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

我不在控制器文件中工作,我不得不把它放在斜杠之间

/ comment here.... /

/ 在这里评论.... /

回答by Miftah Mizwar

In my text editor, i run command + /(sublime-text shortcut). It will be like this.

在我的文本编辑器中,我运行command + /(sublime-text 快捷方式)。它会是这样的。

<%
=begin%>
    Here is the comment 
<%
=end%>

It doesn't look simply, but it works.

它看起来并不简单,但确实有效。