Rails去除Html标签
#ModuleActionView::Helpers::SanitizeHelper
*actionpack/lib/action_view/helpers/sanitize_helper.rbstrip_tags(html)Strips all
HTML tags from the
html, including comments. This uses the html-scanner tokenizer and so its
HTML parsing ability is limited by that of html-scanner.Examplesstrip_tags(
“Strip these tags!”)
=> Strip these tags!
strip_tags(
“Bold no more! See more here…”)
=> Bold no more! See more here…
strip_tags(
“<div id='top-bar'>Welcome to my website!</div>”)
=> Welcome to my website!Source:
hide# File actionpack/lib/action_view/helpers/sanitize_helper.rb, line 83
def
strip_tags(
html)
self.
class.
full_sanitizer.
sanitize(
html).
try(
:html_safe)
endActionController::Base.helpers.strip_tags参考文章: