Module: ActionView::Helpers::TagHelper

Includes:
ERB::Util
Included in:
InstanceTag
Defined in:
lib/action_view/helpers/tag_helper.rb

Overview

This is poor man’s Builder for the rare cases where you need to programmatically make tags but can’t use Builder.

Instance Method Summary collapse

Instance Method Details

#content_tag(name, content, options = {}) ⇒ Object

Examples:

  • content_tag("p", "Hello world!") => <p>Hello world!</p>

  • content_tag("div", content_tag("p", "Hello world!"), "class" => "strong") => <div class="strong"><p>Hello world!</p></div>



21
22
23
# File 'lib/action_view/helpers/tag_helper.rb', line 21

def (name, content, options = {})
  "<#{name}#{tag_options(options)}>#{content}</#{name}>"
end

#tag(name, options = {}, open = false) ⇒ Object

Examples:

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

  • tag("input", { "type" => "text"}) => <input type="text" />



13
14
15
# File 'lib/action_view/helpers/tag_helper.rb', line 13

def tag(name, options = {}, open = false)
  "<#{name}#{tag_options(options)}" + (open ? ">" : " />")
end