How would I get the following html output with the content_tag helper?
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
This is what I have currently
content_tag(:ul) do
a=*(1..5)
a.each do |step_number|
content_tag(:li, class: "step") do
puts step_number
end
end
end
Thanks to Peter's Loop & output content_tags within content_tag in helper link below, I was missing concat
on the li
items
content_tag :ul do
items.collect do |step_number|
concat(content_tag(:li, step_number, class: "step"))
end
end
I guess all you have to fix is
content_tag(:ul) do
(1..5).to_a.map do
content_tag(:li, step_number, class: "step)
end.reduce(&:+)
end
That should do the job!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With