instance method tag

Ruby on Rails 3.0.20

Since v2.2.3

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 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

tag(name, options = nil, open = false, escape = true)

Returns an empty HTML tag of type name which by default is XHTML compliant. Set open to true to create an open tag compatible with HTML 4.0 and below. Add HTML attributes by passing an attributes hash to options. Set escape to false to disable attribute value escaping.

Options

The options hash is used with attributes with no value like (disabled and readonly), which you can give a value of true in the options hash. You can use symbols or strings for the attribute names.

Examples

tag("br")
# => <br />

tag("br", nil, true)
# => <br>

tag("input", { :type => 'text', :disabled => true })
# => <input type="text" disabled="disabled" />

tag("img", { :src => "open & shut.png" })
# => <img src="open &amp; shut.png" />

tag("img", { :src => "open &amp; shut.png" }, false, false)
# => <img src="open &amp; shut.png" />

Parameters

name req
options opt = nil
open opt = false
escape opt = true
Source
# File actionpack/lib/action_view/helpers/tag_helper.rb, line 47
      def tag(name, options = nil, open = false, escape = true)
        "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}".html_safe
      end

Defined in actionpack/lib/action_view/helpers/tag_helper.rb line 47 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionView::Helpers::TagHelper

Type at least 2 characters to search.

↑↓ navigate · open · esc close