在Rails的html.erb模板中阻止注释 [英] Block comments in html.erb templates in rails

查看:83
本文介绍了在Rails的html.erb模板中阻止注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何注释掉混有红宝石代码的html?

How do you comment out html mixed with ruby code?

some text <% ... %> more text <%= ... %>
something else
<% ... %>

在jsp中,这非常简单:<%-...- -%> ,但我无法在rails中找到任何简洁的选择。

In jsp it's real simple: <%-- ... --%>, but I'm unable to find any concise option in rails.

简单的html注释< ;!-...-> 不起作用:ruby代码仍在执行并且大喊错误。

Simple html comments <!-- ... --> do not work: ruby code is still executed and yells errors.

可以选择将如果为false 和html注释一起使用,但是它很冗长,更不用说IDE了。 t支持它。

There's an option to use if false with html comments, but it's quite verbose, not to mention IDEs doesn't support it.

还有一个来自纯红宝石的选项,效果出奇。

There's also an option coming from pure ruby, which surprisingly works.

<%
=begin %>
... html and ruby code goes here
<%
=end %>

总体来说还可以,只是它很冗长,外观怪异,而且我所知道的红宝石IDE都不支持它(是的,我想用一个按键来评论/注释掉。)

It's generally fine, except that it's verbose, weird-looking and none of ruby IDEs I know support it (yep, I like to comment/comment-out with one keystroke).

我很好奇,有没有正式的做法?

I'm curious, is there any 'official' of doing this in rails?

谢谢!

推荐答案

我不算是解决方案,但是也许将块围在

I wouldn't count as a solution, but perhaps enclosing the chunk between an

<% if false %>
   ...
<% end %>

或者如果您觉得有点脏,请创建一个仅输出任何内容的助手。

or if you feel a little dirty, create a helper that simply outputs nothing.

我从不需要它,但我偶然发现似乎没有针对此问题的现成解决方案。

I've never needed it, but I'm stumbled there seems to be no out-of-the-box solution for this.

这篇关于在Rails的html.erb模板中阻止注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆