method
strip_links
v3.2.13 -
Show latest stable
- Class:
ActionView::Helpers::SanitizeHelper
strip_links(html)public
Strips all link tags from text leaving just the link text.
Examples
strip_links('<a href="http://www.rubyonrails.org">Ruby on Rails</a>') # => Ruby on Rails strip_links('Please e-mail me at <a href="mailto:[email protected]">[email protected]</a>.') # => Please e-mail me at [email protected]. strip_links('Blog: <a href="http://www.myblog.com/" class="nav" target=\"_blank\">Visit</a>.') # => Blog: Visit.
1Note
strip_links method not functioning in controllers, models, or libs
It comes up with an error about white_list_sanitizer undefined in the class you're using it in. To get around this, use:
ActionController::Base.helpers.strip_links('string')
To shorten this, add something like this in an initializer:
class String
def strip_links
ActionController::Base.helpers.strip_links(self)
end
end
then call it with:
'string'.strip_links