2017-03-10 255 views
1

我想在我看來嵌套div標籤

<div class="progress "> 
    <div class="progress-bar bgclre3559b" role="progressbar" style="width:80%"> 
    <span><%= top_cat.first %></span> 
    </div> 
    <div class="progress-bar bgclre3559b" role="progressbar" style="width:15%"> 
    <span class="clrfff"><%= "#{top_cat.last}%" %></span> 
    </div> 
</div> 

達到這個HTML代碼,我想這一個,但它只能說明裏面的第二個div。有沒有辦法連接它們或如何正確顯示在rails方式。

content_tag :div, class: "progress" do 
    content_tag :div, class: "progress-bar bgclre3559b", role: "progressbar", style: "width: 80%" do 
    content_tag :span, top_cat.first 
    end 
    content_tag :div, class: "progress-bar bgclre3559b", role: "progressbar", style: "width: 15%" do 
    content_tag :span, "#{top_cat.last}%" 
    end 
end 

在此先感謝!

回答

0

如果有人需要解決此類問題,我找到了答案。我改變了我的幫手文件中的代碼。

first = 
    content_tag :div, class: "progress-bar bgclre3559b", role: "progressbar", style: "width: 80%" do 
     content_tag :span, top_cat.first 
    end 
second = 
    content_tag :div, class: "progress-bar bgclre3559b", role: "progressbar", style: "width: 15%" do 
     content_tag :span, "#{top_cat.last}%" 
    end 

content_tag :div, class: "progress" do 
    first.concat(second).html_safe 
end