为什么会:
应用/助手/ 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>
答案 0 :(得分:2)
在+
方法之间添加content_tag()
:
def my_test
content_tag(:p, "One") + \
content_tag(:p, "Two")
end
Ruby只返回该方法的最后一个表达式。要返回所有需要的html,您应该将其添加到另一个。