0
4

1 回答 1

0

sanitize在将其标记为 html_safe 之前,您需要使用帮助程序。不幸的是,在这种情况下,黑名单功能已被删除,因此除了默认值外,您还需要逐字列出您想要的所有属性。使用正则表达式删除有问题的属性可能更容易。

此外,对于它的价值,它的raw(event.description)作用与 相同event.description.html_safe,但不会因 nil 值而崩溃(不确定您的验证规则是什么),因此通常首选它。

编辑:

清理示例用法(来自http://apidock.com/rails/v3.2.8/ActionView/Helpers/SanitizeHelper/sanitize):

truncate( raw( sanitize(event.description, :tags => %w(table tr td), :attributes => %w(id class style) ) ), :length => 110, :omission => "...")

注意:像这样截断 HTML 会导致一些奇怪且难以追踪的错误,因为会因为截断结束标签而创建无效的 HTML。

于 2012-09-06T05:36:58.973 回答