Rails Return multiple content_tags from Helper module

匿名 (未验证) 提交于 2019-12-03 02:22:01

问题:

I've written the following helper:

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 

It is currently parsed these arrays.

["paragraph", "This is the first paragraph."] ["paragraph", "This is the second.", "And here's an extra paragraph."] 

And it returns:

<p>This is the first paragraph.</p> <p>This is the second.</p> 

Is there a way to accumulate the content_tag? so it returns:

<p>This is the first paragraph.</p> <p>This is the second.</p> <p>And here's an extra paragraph.</p> 

My only solution right now is to use a partial instead. But that's going to get very messy once I starting adding more to case condition.

回答1:

Use #concat:

http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-concat

this thread can be helpful:

rails, How to build table in helper using content_tag?



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!