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>
但是,它給了我意想不到的事情(爲了提高可讀性,我添加了新行 - 原文中的所有內容都在一行中):
<div class="some-class" role="alert">
<button class="close" type="button">
<span><b>Some bold text</b>and nothing more</span>
</button>
</div>
我不太明白,如何將兩個嵌套content_tag
s合併成一個:safe
字符串,同時使這個字符串"<span><b>Some bold text</b>and nothing more</span>"
安全並且不會被轉義。