instance method html_escape

Ruby on Rails 2.2.3

Last seen in v7.0.10

Available in: v2.2.3 v2.3.18 v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10

Signature

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 &gt; 0 &amp; a &lt; 10?

Parameters

s req
Source
# File actionpack/lib/action_view/template_handlers/erb.rb, line 17
    def html_escape(s)
      s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
    end

Defined in actionpack/lib/action_view/template_handlers/erb.rb line 17 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ERB::Util

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close