# Help putting this code into plugin

**URL:** <https://www.ruby-forum.com/t/help-putting-this-code-into-plugin/91946>\
**Category:** Rails\
**Created:** [April 13, 2007, 6:29pm UTC](https://www.ruby-forum.com/t/help-putting-this-code-into-plugin/91946 "2007-04-13T18:29:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![scot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/77aa72/32.png) [@scot](https://www.ruby-forum.com/u/scot)\
**Post date:** [April 13, 2007, 6:29pm UTC](https://www.ruby-forum.com/t/help-putting-this-code-into-plugin/91946/1 "2007-04-13T18:29:40Z")

</div>

Hi,

I have the following code that allows me to call before\_validation  
:acts\_as\_tagless in my models.

I would like to put this into aplugin so I can do somthing like  
acts\_as\_tagless :fieldName, :fieldName, :etc

any suggestions on where to start?

Thanks,  
Scot

```
#
#removes html tags
def acts_as_tagless

    string_attributes = {}
    self.attributes.each do |each_name, each_attribute|
        if each_attribute.kind_of? String
          string_attributes[each_name] = strip_tags(each_attribute)
        end
    end
    self.attributes = string_attributes

end

```

# 

```
#strip_tags function taken from ActionView
def self.strip_tags(html)
    if html.index("<")
        text = ""
        tokenizer = HTML::Tokenizer.new(html)

        while token = tokenizer.next
            node = HTML::Node.parse(nil, 0, 0, token, false)
            # result is only the content of any Text nodes
            text << node.to_s if node.class == HTML::Text
        end
            # strip any comments, and if they have a newline at the

```

end (ie. line with  
# only a comment) strip that too  
text.gsub(/[\n]?/m, “”)  
else  
html # already plain text  
end  
end
