我写了以下助手:
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>
我现在唯一的解决方案是使用部分代替。但是一旦我开始在案例条件中添加更多内容,这将变得非常混乱。