# Using ActionView from rails in custom filter plugin

**URL:** <https://discuss.elastic.co/t/using-actionview-from-rails-in-custom-filter-plugin/106248>\
**Category:** Logstash\
**Created:** [November 2, 2017, 8:51pm UTC](https://discuss.elastic.co/t/using-actionview-from-rails-in-custom-filter-plugin/106248 "2017-11-02T20:51:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanmcclure4](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryanmcclure4/32/23712_2.png) [@ryanmcclure4](https://discuss.elastic.co/u/ryanmcclure4)\
**Post date:** [November 2, 2017, 8:51pm UTC](https://discuss.elastic.co/t/using-actionview-from-rails-in-custom-filter-plugin/106248/1 "2017-11-02T20:51:36Z")

</div>

I'm trying to write a filter plugin which will strip html tags from a given event property. I'd rather not re-invent the wheel so I was trying to find a gem that already included this function. I found 'sanitizer' and spent hours trying to install it to no avail (due to some missing dev tool errors on my mac, but that's a whole other story...). I then came across _ActionView::Base.full\_sanitzer.sanitize_, which should do exactly what I want. So I tried requiring action\_view and using it, but this ends up messing up the filter and throwing a logstash error "Couldn't find any filter plugin named 'sanitizer'".

Here is my plugin code:

```
# encoding: utf-8
require "logstash/filters/base"
require "logstash/namespace"
require "action_view"

class LogStash::Filters::Sanitizer < LogStash::Filters::Base

  config_name "sanitizer"

  config :field, :validate => :string, :required => true

  public
  def register
  end # def register

  public
  def filter(event)

    # get specified event field
    @content = event.get(@field)

    # sanitize content
    @sanitized = ActionView::Base.full_sanitizer.sanitize(@content)

    # update event with sanitized content
    event.set(@field, @sanitized)

    # filter_matched should go in the last line of our successful code
    filter_matched(event)

  end # def filter
end # class LogStash::Filters::Sanitize

```

I'm new to Ruby, so please excuse my ignorance 🙂

I tried this solution, as I saw it being done similarly [here](https://stackoverflow.com/questions/6853015/how-do-i-use-an-actionviewhelper-in-a-ruby-script-outside-of-rails).

Am I missing something obvious here?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 30, 2017, 8:51pm UTC](https://discuss.elastic.co/t/using-actionview-from-rails-in-custom-filter-plugin/106248/2 "2017-11-30T20:51:46Z")

</div>

Closed on November 30, 2017, 8:51pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
