content_tag
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- 7.2.3 (0)
- 8.0.0
- 8.1.1
- What's this?
content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
public
Returns an HTML block tag of type name surrounding the content. Add HTML attributes by passing an attributes hash to options. Instead of passing the content as an argument, you can also use a block in which case, you pass your options as the second parameter. Set escape to false to disable escaping. Note: this is legacy syntax, see tag method description for details.
Options
The options hash can be 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
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> content_tag(:div, "Hello world!", class: ["strong", "highlight"]) # => <div class="strong highlight">Hello world!</div> content_tag(:div, "Hello world!", class: ["strong", { highlight: current_user.admin? }]) # => <div class="strong highlight">Hello world!</div> content_tag("select", options, multiple: true) # => <select multiple="multiple">...options...</select> <%= content_tag :div, class: "strong" do -%> Hello world! <% end -%> # => <div class="strong">Hello world!</div>

