避免在HTML中呈现评论
答
如果我理解正确的问题,你问的Ruby/Rails评论VS HTML注释......这给你的观点一试:
<!-- This is an HTML comment and will show up in the HTML source! -->
现在试试这个:
<%# This is a comment that won't show up in the HTML source! %>
<%#
You can even use this for commenting multiple lines!
How useful!
%>
这有帮助吗?
答
使用= begin和= end标记您的评论
+0
这是要走的路。 – 2010-08-08 00:16:13
答
有没有简单的方法来做到这一点的开始和结束。也许,你可以猴子修补ERB的来源,但它有点讨厌。
答
我不是一个Rails程序员,但一个快速的暴食,但提出了这个链接: http://blog.brijeshshah.com/strip-tags-in-rails-javascript-and-php/
他使用的方法是一个我已经在过去,你sanitize
视图的输出使用。 sanitize
是在渲染视图之前要使用的函数的名称。
答
的hackish的种类,但你可以在一个辅助方法
把它包在你看来:
<% comment do %>
<%= "this won't be executed" %>
or displayed
<% end %>
在app/helpers/application_helper.rb
module ApplicationHelper
def comment(&block)
## you can do something with the block if you want
end
end
哇!这样简单的解决方案!谢谢! – AntonAL 2010-08-14 07:52:37