简体   繁体   中英

nested div tags in rails

I want to achieve this HTML code in my view

<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>

I tried this one but it only shows the second div inside. Is there a way to concatenate them or how to display properly in rails way.

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

Thanks in advance!

I found an answer in case if someone need to solve such problem. I changed the code in my helper file like this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM