ste*_*ble 1 ruby loops for-loop return
以下声明......
content_tag(:li, concept.title)
Run Code Online (Sandbox Code Playgroud)
...返回类似于:
<li>"My big idea"</li>
Run Code Online (Sandbox Code Playgroud)
调用时,以下方法定义返回相同的内容:
def list_of_concepts(part)
content_tag(:li, concept.title)
end
Run Code Online (Sandbox Code Playgroud)
同样......
def list_of_concepts(part)
content_tag(:li, part.concepts.first.title)
end
Run Code Online (Sandbox Code Playgroud)
但是以下......
def list_of_concepts(part)
for concept in part.concepts
content_tag(:li, concept.title)
end
end
Run Code Online (Sandbox Code Playgroud)
...... #在我看来,只是给了我一堆英镑符号(" "),就像它返回真或假或计数而不是任何content_tag回报.我怎样才能让它返回什么content_tag回报?
再次感谢,
史蒂芬.
for循环不会返回您的数据,请尝试以下方法:
def list_of_concepts(part)
part.concepts.map { |c| content_tag(:li, c.title) }.join
end
Run Code Online (Sandbox Code Playgroud)