Remove all html tags from attributes in rails

Posted by Hock on Stack Overflow See other posts from Stack Overflow or by Hock
Published on 2010-04-05T00:17:04Z Indexed on 2010/04/05 0:23 UTC
Read the original article Hit count: 636

Filed under:
|

I have a Project model and it has some text attributes, one is summary. I have some projects that have html tags in the summary and I want to convert that to plain text. I have this method that has a regex that will remove all html tags.

def strip_html_comments_on_data
  self.attributes.each{|key,value| value.to_s.gsub!(/(<[^>]+>|&nbsp;|\r|\n)/,"")}
end

I also have a before_save filter

before_save :strip_html_comments_on_data

The problem is that the html tags are still there after saving the project. What am I missing?

And, is there a really easy way to have that method called in all the models?

Thanks,

Nicolás Hock Isaza

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about regex