为auto_html创建过滤器

Mir*_* H. 7 ruby-on-rails-3

我想为auto_html创建一个自定义过滤器.我在哪里放过滤器以便我可以使用它?文档没有涉及任何内容.谢谢!

Leo*_*Leo 6

我采用的方法是将代码添加到初始化文件中,例如:

/path/to/your/application/config/initializers/auto_html.rb

然后你可以写下这样的东西:

AutoHtml.add_filter(:change_colours).with({}) do |text, options|
  text.gsub("#FF0000", "#00FF00")
end 
Run Code Online (Sandbox Code Playgroud)

并打电话给auto_html(input) { change_colours }你的模型.空哈希将采用您关心的任何选项传递给过滤器.