避免在HTML中呈现评论

问题描述:

我在Rails视图中有很多评论。避免在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! 
%> 

这有帮助吗?

+0

哇!这样简单的解决方案!谢谢! – AntonAL 2010-08-14 07:52:37

使用= 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 

也许你可以使用Haml的Comments: -#允许发表评论你的haml代码没有出现在生成的html中。