class method
self.html_escape
Ruby on Rails 3.1.12
Since v2.3.18 Last seen in v7.0.10Signature
self.html_escape(s)
A utility method for escaping HTML tag characters. This method is also aliased as h.
In your ERB templates, use this method to escape any unsafe content. For example:
<%=h @person.name %>
Example:
puts html_escape("is a > 0 & a < 10?") # => is a > 0 & a < 10?
Parameters
-
sreq
Source
# File activesupport/lib/active_support/core_ext/string/output_safety.rb, line 19
def html_escape(s)
s = s.to_s
if s.html_safe?
s
else
s.gsub(/[&"'><]/, HTML_ESCAPE).html_safe
end
end
Defined in activesupport/lib/active_support/core_ext/string/output_safety.rb line 19
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ERB::Util