我写了以下助手:
def section_to_html (block)
case block[0].downcase
when "paragraph"
block.shift
block.each do |value|
return content_tag(:p, value)
end
end
end
当前正在解析这些数组。
["paragraph", "This is the first paragraph."]
["paragraph", "This is the second.", "And here's an extra paragraph."]
它返回:
<p>This is the first paragraph.</p>
<p>This is the second.</p>
有没有办法积累content_tag?所以它返回:
<p>This is the first paragraph.</p>
<p>This is the second.</p>
<p>And here's an extra paragraph.</p>
我现在唯一的解决方案是使用部分代替。但一旦我开始向案例条件添加更多内容,情况就会变得非常混乱。
使用#concat:
http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-concat
该线程可能会有所帮助:
Rails,如何使用 content_tag 在助手中构建表?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)