我写了以下帮助程序:

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, How to build table in helper using content_tag?

关于html - Rails从Helper模块返回多个content_tags,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15726417/

10-13 06:37