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
ActiveSupport is the only Rails framework that supports cherry-picking individual components. The other frameworks, including ActionView, must be required en-masse:
require 'action_view'
Note that this require won't necessarily load all of ActionView. Barring situations where thread-safety requires that autoloads happen eagerly, it merely sets up autoloads and requires common dependencies. That means that following the require, if you reference, e.g. ActionView::Helpers::SanitizeHelper, it will cause action_view/helpers /sanitize_helper.rb to be required.
Therefore the correct, supported way to accomplish what you desire using ActionView is the following:
require 'action_view'
class Test < Test::Unit::TestCase # or whatever
include ActionView::Helpers::SanitizeHelper
def my_test
assert_equal "lol", strip_tags("lol")
end
end
This isn't well-documented; I based this answer primarily off of the discussion on this issue.