La mejor manera de agregar comentarios en erb


¿Cómo añadimos comentarios en archivos erb, si no queremos que se generen en el contenido html?

Author: thumbtackthief, 2010-05-05

5 answers

Utilice la secuencia <%# %>, por ejemplo,

<%# This is a great comment! %>
 300
Author: John Douthat,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-05 15:59:53

Para el Registro

<%# This is a great comment! %>

<%#= This is a great comment! %>
 44
Author: Salil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-05 16:25:57

Para los comentarios de bloque:

<% if false %>
    code to be commented out...
<% end %> 
 25
Author: Tim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-19 18:08:52

Tengo una configuración de Windows, y esta secuencia es la única que funciona para mí:

Ejemplo:

<%-# This is a sample comment! %>
 6
Author: Edward Castaño,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-10-26 18:56:52

Desde entonces .erb es por definición "embedded ruby", puede incrustar cada código ruby entre: <%= y el otro: %>, normalmente todo escrito en una línea. Además, los comentarios de una línea de ruby comienzan siempre con #, por lo que el estilo <%=# Comment %> coincide perfectamente con los estilos pure-ruby y erb para comentarios de una línea.

 2
Author: Maaaaaaarco,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-05 10:36:42