2016-07-08 27 views
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"> 
    &times; 
    </button> 
    <button class="close" type="button"> 
    &times; 
    </button> 
    <span><b>Some bold text</b>and nothing more</span> 
</div> 

しかし、それは私の予想外の何かを与えます(私は可読性のために新しい行を追加しました - オリジナルではすべてが1行にあります)。

<div class="some-class" role="alert"> 
    <button class="close" type="button"> 
    &lt;span&gt;&lt;b&gt;Some bold text&lt;/b&gt;and nothing more&lt;/span&gt; 
    </button> 
</div> 

私は実際に理解していない、どのように2つのネストされたcontent_tagを1つの:safe文字列に入れ、同時にこの文字列を"<span><b>Some bold text</b>and nothing more</span>"にして安全にエスケープしないようにする。

答えて

3

私はほとんどそれを理解したように見えます。このコードは次のようになります。

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, ["&times;"]} 
    end 
    end, 
    content_tag(:button, type: :button, class: "close") do 
    content_tag(:span, class: "some-other-class") do 
     {:safe, ["&times;"]} 
    end 
    end, 
    {:safe, ["<span><b>Some bold text</b>and nothing more</span>"]}] 
end 
関連する問題