在Y循环中创建一个for X将返回它包含的语句返回的内容
题
以下陈述......
content_tag(:li, concept.title)
...返回类似的内容:
<li>"My big idea"</li>
以下方法定义在调用时返回相同的内容:
def list_of_concepts(part)
content_tag(:li, concept.title)
end
同样......
def list_of_concepts(part)
content_tag(:li, part.concepts.first.title)
end
但以下......
def list_of_concepts(part)
for concept in part.concepts
content_tag(:li, concept.title)
end
end
...在我看来,只是给了我一堆符号(“#
”),比如它返回true或false或者是一个计数而不是 content_tag 代码>返回。如何让它返回
content_tag
返回的内容?
再次感谢,
史蒂芬。
解决方案
for循环不会返回您的数据,请尝试:
def list_of_concepts(part)
part.concepts.map { |c| content_tag(:li, c.title) }.join
end
不隶属于 StackOverflow