rails中嵌套的div标签

时间:2017-03-10 10:34:55

标签: ruby-on-rails ruby ruby-on-rails-4 nested content-tag

我想在我的视图中实现此HTML代码

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

我尝试了这个,但它只显示了第二个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

提前致谢!

1 个答案:

答案 0 :(得分: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