如何评论Rails视图中的代码? [英] How to comment code in Rails views?

查看:123
本文介绍了如何评论Rails视图中的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Rails和开发视图时,我经常想注释掉代码。简单足够与类&模型,但观看次数有点棘手。

As I'm playing with Rails and developing views I often want to comment out code. Simple enough with classes & models but views are a bit more tricky.

在视图中注释代码的最佳方法是,它不会被解释,好吧,任何东西... HTML给我们<! - 评论Rails代码在这里 - > 虽然这里的代码似乎解释了吗?还是有更多的Railsy方式?

What's best way to comment code in a view so it's not interpreted by, well, anything... HTML gives us <!-- commented Rails code here --> though code enclosed here seems to get interpreted anyway?!? Or is there a more Railsy way?

推荐答案

<%code code#comment%> USED工作,偶然。

<% code code # comment %> USED to work but I think that was accidental.

您始终应在单独的注释标签中注释注释<%#comment%>

You were always supposed to put comments in separate comment tags <%# comment %>

注释

现在,旧的漏洞被关闭了(我忘记'now'是指Ruby 1.8还是Rails 3或者什么),所以:

Now the old loophole is closed (I forget whether 'now' means Ruby 1.8 or Rails 3 or what) so that:

<%code code#this runs too%>
<%#也运行%>
<%#注释掉的唯一方法%>

<% code code # this runs too %> <% # also runs %> <%# the only way to comment out %>

这篇关于如何评论Rails视图中的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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