Manuk Karapetyan
Manuk Karapetyan

Reputation: 534

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!

Upvotes: 1

Views: 668

Answers (1)

Manuk Karapetyan
Manuk Karapetyan

Reputation: 534

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

Upvotes: 0

Related Questions