无法将两个content_tags放在一个帮助器方法中?

时间:2015-09-13 20:12:29

标签: ruby-on-rails

为什么会:

应用/助手/ application_helper.rb

def my_test
  content_tag(:p, "One")
  content_tag(:p, "Two")
end

应用/视图/主/ index.html.erb

<%= my_test %>

结果:

<p>Two</p>

而不是:

<p>One</p>
<p>Two</p>

1 个答案:

答案 0 :(得分:2)

+方法之间添加content_tag()

def my_test
  content_tag(:p, "One") + \
  content_tag(:p, "Two")
end

Ruby只返回该方法的最后一个表达式。要返回所有需要的html,您应该将其添加到另一个。