我正在尝试使用ActionView中的Sanitize方法。Rails:使用ActionView方法清理Lib中的错误
线r_str = Helper.instance.sanitize(r_str, :tags => @@allowed_tags, :attributes => @@allowed_attribs)
是给我的错误
undefined method `white_list_sanitizer' for Parsers::HTML::Helper:Class
这是我在lib/parsers.rb
module Parsers
module HTML
@@allowed_tags = %w(--snip--)
@@allowed_attribs = %w(--snip--)
class Helper
include Singleton
include ActionView::Helpers::SanitizeHelper
end
#Use built-in santizer and the Hpricot plugin
def self.clean(str)
rgx = /<code>(.*?)<\/code>/ #All html within a code tag should be escaped.
r_str = str.gsub(rgx) { |match| "<code>" + CGI.escapeHTML(match[5..-7]) + "</code>" } # TODO: test this.
r_str = Helper.instance.sanitize(r_str, :tags => @@allowed_tags, :attributes => @@allowed_attribs)
Hpricot(r_str)
end
end
--snip--
end
代码我在做什么错?
(请不要允许用户提交HTML的危险性发表意见,我所知道的风险)
我不知道为什么选择这个答案......这些都不工作了我。 – bchurchill 2013-02-20 21:10:29