I need to turn HTML into plain text. There\'s a nice function that does that in ActionView\'s SanitizeHelper, but I have trouble understanding how I can reference it and use
I believe this should be enough:
"lol".gsub(/<[^>]*>/ui,'') #=> lol
You can use Nokogiri as well:
require 'rubygems'
require 'nokogiri'
doc = Nokogiri::HTML("lol")
doc.text #=> "lol"
You still can go with the Rails one by doing something like:
require 'rubygems'
require 'action_view'
class Foo
include ActionView::Helpers::SanitizeHelper
def test
strip_tags("lol")
end
end
f = Foo.new
puts f.test #=> lol