为auto_html创建过滤器

时间:2012-06-06 06:29:02

标签: ruby-on-rails-3

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

1 个答案:

答案 0 :(得分:6)

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

<强> /path/to/your/application/config/initializers/auto_html.rb

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

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

并在模型中调用auto_html(input) { change_colours }。空哈希将采用您想要传递给过滤器的任何选项。