【发布时间】:2013-12-04 21:26:21
【问题描述】:
如何使用 content_tag 帮助程序获得以下 html 输出?
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
这是我目前拥有的
content_tag(:ul) do
a=*(1..5)
a.each do |step_number|
content_tag(:li, class: "step") do
puts step_number
end
end
end
更新 - 回答
感谢 Peter 在下面的 Loop & output content_tags within content_tag in helper 链接,我在 li 项目上缺少 concat
content_tag :ul do
items.collect do |step_number|
concat(content_tag(:li, step_number, class: "step"))
end
end
【问题讨论】:
-
(我认为 splat
*不会像您认为的那样做。)您目前有什么输出? -
@Phlip 他似乎只是要创建一个用于迭代的数组,在这种情况下,splat a) 将不起作用并且 B) 没有必要... OP:尝试 (1.. 5).每个都做... ;)
-
如何将此解决方案用于嵌套的解决方案
标签: html ruby-on-rails content-tag