在 rails 中嵌套了 div 个标签
nested div tags in rails
我想实现这个 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
提前致谢!
如果有人需要解决此类问题,我找到了答案。我像这样更改了帮助文件中的代码。
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
我想实现这个 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
提前致谢!
如果有人需要解决此类问题,我找到了答案。我像这样更改了帮助文件中的代码。
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