gpt4 book ai didi

ruby-on-rails - 嵌套的 content_tags 只显示最后一个 chilldren rails view helper

转载 作者:太空宇宙 更新时间:2023-11-03 17:18:09 25 4
gpt4 key购买 nike

我正在尝试做一个可重用的小 helper ,以将一些带有内容标签的描述插入到页面中

def spec_description(name, overview, detail)
content_tag :dl do
content_tag :dt do
content_tag(:strong, name)
end
content_tag :dd, overview, :class => "spec-overview"
content_tag :dd, detail, :class => "spec-detail" #only this dd tag gets output
end
end

但事实上,只有带有“详细信息”的 dd 标签才会输出到 html

已更新现在输出 html 是这样的:

<dl>
<dd>some detail from detail variable</dd>
</dl>

看看“overview”和“name”dd 标签怎么完全不见了?更不用说他们的内容了……

有谁知道这是为什么以及我该如何解决它?

最佳答案

你的助手正在返回一些 HTML,它的返回值是 content_tag :dl。返回。 <dl>的内容将是它的 block 返回的任何内容并且该 block 返回最后一个值(即最后一个 <dd> )。所以你只是有一个返回值问题:

def spec_description(name, overview, detail)
content_tag :dl do
html = content_tag :dt { content_tag(:strong, name) }
html += content_tag :dd, overview, :class => "spec-overview"
html += content_tag :dd, detail, :class => "spec-detail"
html
end
end

关于ruby-on-rails - 嵌套的 content_tags 只显示最后一个 chilldren rails view helper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7631028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com