Rails从Helper模块中返回多个content_tags [英] Rails Return multiple content_tags from Helper module

查看:161
本文介绍了Rails从Helper模块中返回多个content_tags的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了以下帮助程序:

  def section_to_html(block)
case block [0]。当段落
block.shift
block.each do | value |时,会降低

return content_tag(:p,value)
end
end
end

目前正在分析这些数组。

  [段落,这是第一段。 ] 
[paragraph,This is the second。,这是一个额外的段落。]

并返回:

 < p>这是第一段。< / p> 
< p>这是第二个。< / p>

有没有办法累积content_tag?所以它会返回:

 < p>这是第一段。< / p> 
< p>这是第二个。< / p>
< p>这里有一个额外的段落。< / p>

现在我唯一的解决方案是使用partial。但是,一旦我开始为案例条件添加更多内容,这会变得非常混乱。使用#concat:

解决方案

b
$ b

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



此主题可能有所帮助:

p>

rails,如何使用content_tag在助手中构建表?


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.

解决方案

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?

这篇关于Rails从Helper模块中返回多个content_tags的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆