1

以下声明...

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返回?

再次感谢,

史蒂文。

4

1 回答 1

7

the for loop doesn't return your data, try this:

def list_of_concepts(part)
  part.concepts.map { |c| content_tag(:li, c.title) }.join
end
于 2009-09-17T12:56:36.047 回答