在Y循环中创建一个for X将返回它包含的语句返回的内容

以下声明……

content_tag(:li, concept.title) 

…返回类似于:

 
  • "My big idea"
  • 调用时,以下方法定义返回相同的内容:

     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或count,而不是content_tag返回。 如何让它返回content_tag返回的内容?

    再次感谢,

    史蒂芬。

    for循环不会返回您的数据,请尝试以下方法:

     def list_of_concepts(part) part.concepts.map { |c| content_tag(:li, c.title) }.join end