2013-03-31 60 views
2

多個content_tags我寫了下面的幫助:Rails的返回從輔助模塊

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> 

我現在唯一的解決方案是使用部分代替。但是一旦我開始增加更多的案件條件,這將變得非常混亂。

回答