Ruby on rails 无法在单个帮助器方法中放置两个content_标记?
为什么会: app/helpers/application\u helper.rbRuby on rails 无法在单个帮助器方法中放置两个content_标记?,ruby-on-rails,Ruby On Rails,为什么会: app/helpers/application\u helper.rb def my_test content_tag(:p, "One") content_tag(:p, "Two") end <%= my_test %> app/views/main/index.html.erb def my_test content_tag(:p, "One") content_tag(:p, "Two") end <%= my_test %>
def my_test
content_tag(:p, "One")
content_tag(:p, "Two")
end
<%= my_test %>
app/views/main/index.html.erb
def my_test
content_tag(:p, "One")
content_tag(:p, "Two")
end
<%= my_test %>
结果:
<p>Two</p>
两个
而不是:
<p>One</p>
<p>Two</p>
一个
两个
在2个内容标签()之间添加+
方法:
def my_test
content_tag(:p, "One") + \
content_tag(:p, "Two")
end
Ruby只返回方法中的最后一个表达式。要返回所有需要的html,您应该将一个html添加到另一个html