1
を削除し、私は私のプロジェクトでは、このような構造を持っている:フェニックスと複数の子を持つネストされたcontent_tagsは、ネストされたコンテンツ
content_tag(:div, class: "some-class", role: "alert") do
content_tag(:button, type: :button, class: "close") do
content_tag(:span, class: "some-other-class") do
{:safe, ["×"]}
end
end
content_tag(:button, type: :button, class: "close") do
content_tag(:span, class: "some-other-class") do
{:safe, ["×"]}
end
end
"<span><b>Some bold text</b>and nothing more</span>"
end
そしてそれは、このようなHTMLを生成することを期待:
<div class="some-class" role="alert">
<button class="close" type="button">
×
</button>
<button class="close" type="button">
×
</button>
<span><b>Some bold text</b>and nothing more</span>
</div>
しかし、それは私の予想外の何かを与えます(私は可読性のために新しい行を追加しました - オリジナルではすべてが1行にあります)。
<div class="some-class" role="alert">
<button class="close" type="button">
<span><b>Some bold text</b>and nothing more</span>
</button>
</div>
私は実際に理解していない、どのように2つのネストされたcontent_tag
を1つの:safe
文字列に入れ、同時にこの文字列を"<span><b>Some bold text</b>and nothing more</span>"
にして安全にエスケープしないようにする。