Rails从Helper模块返回多个content_tags
我写了以下帮助:
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."]
它返回:
This is the first paragraph.
This is the second.
有没有办法累积content_tag? 所以它返回:
This is the first paragraph.
This is the second.
And here's an extra paragraph.
我现在唯一的解决方案就是使用部分解决方案。 但是,一旦我开始添加更多案例条件,这将变得非常混乱。
使用#concat:
http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-concat
这个主题可能会有所帮助:
rails,如何使用content_tag在帮助器中构建表?