Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Purifier equivalent for Ruby on Rails?

Has anyone encountered an equivalent to HTMLPurifier for Rails apps? Essentially I need to clean up often terribly formed HTML generated by users before saving to the DB.

http://htmlpurifier.org/

like image 226
glimpse nirvana Avatar asked Jun 18 '11 13:06

glimpse nirvana


1 Answers

You can use the sanitize method.

sanitize(html)

There is also a Sanitize gem.

Sanitize.clean(html)

I tend to prefer the Sanitize gem because it can be used as a before_save filter in your models instead of having to use the sanitize method in each of your views.

like image 89
Mikhail Nikalyukin Avatar answered Oct 05 '22 20:10

Mikhail Nikalyukin