method
strip_links
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:me@email.com">me@email.com</a>.') # => Please e-mail me at me@email.com. strip_links('Blog: <a href="http://www.myblog.com/" class="nav" target=\"_blank\">Visit</a>.') # => Blog: Visit
Register or
log in
to add new notes.
k776 -
April 21, 2009
0 thanks
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