Incerteza
Incerteza

Reputation: 34934

Content_tag escapes the data

span_tag = content_tag(:span, class: "123")

It generates the following html:

<span>{:class=&gt;&quot;123&quot;}</span>

I wonder, what's up with this? Shouldn't it be just <span class="123"></span> which is exactly what I want? Do I necessarily have to use .html_safe?

Upvotes: 1

Views: 185

Answers (2)

Roman Kiselenko
Roman Kiselenko

Reputation: 44380

From doc

content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)

pass empty block:

span_tag = content_tag(:span, class: "123") {}
"<span class=\"123\"></span>"
span_tag = content_tag(:span, class: "123") { 'foo' }
"<span class=\"123\">foo</span>"

Upvotes: 0

xdazz
xdazz

Reputation: 160953

Try:

span_tag = content_tag(:span, nil, class: "123")

Upvotes: 5

Related Questions