span_tag = content_tag(:span, class: "123")
它生成以下html:
<span>{:class=>"123"}</span>
我想知道,这是什么?难道不仅仅是<span class="123"></span>
这正是我想要的吗?我是否必须使用.html_safe
?
答案 0 :(得分:5)
尝试:
span_tag = content_tag(:span, nil, class: "123")
答案 1 :(得分:0)
来自doc
content_tag(name,content_or_options_with_block = nil,options = nil, escape = true,&amp; 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>"