我希望使用标记帮助器将html呈现到视图中,该方法在helper模块中声明,但不起作用。我想呈现的html代码如下:
<span class="flex w-5 h-5 ml-3">
<span class="animate-ping inline-flex h-full w-full rounded-full aspect-square bg-indigo-400 opacity-75"></span>
<span class="relative inline-flex w-5 h-5 rounded-full bg-indigo-500 text-gray-200 justify-center aspect-square right-5">
<%= current_user_active_count %>
</span>
</span>在助手中实际编写的代码如下:
tag.span class: "flex w-5 h-5 ml-3" do
tag.span class: "animate-ping inline-flex h-full w-full rounded-full aspect-square bg-indigo-400 opacity-75"
tag.span current_user_active_count, class: "relative inline-flex w-5 h-5 rounded-full bg-indigo-500 text-gray-200 justify-center aspect-square right-5"
end此代码呈现的html如下:
<span class="flex w-5 h-5 ml-3">
<span class="relative inline-flex w-5 h-5 rounded-full bg-indigo-500 text-gray-200 justify-center aspect-square right-5">
<%= current_user_active_count %>
</span>
</span>如上面所示,两个嵌套标记中的第一个标记被忽略,并且只呈现第二个标记。我认为这是一个写作风格的问题,但我如何呈现所需的html呢?
如果你能给我建议,我会很感激的。
发布于 2022-11-30 10:07:55
可以使用concat将内容累积到输出缓冲区中:
tag.span class: "flex w-5 h-5 ml-3" do
concat tag.span(class: "animate-ping inline-flex h-full w-full rounded-full aspect-square bg-indigo-400 opacity-75")
concat tag.span(current_user_active_count, class: "relative inline-flex w-5 h-5 rounded-full bg-indigo-500 text-gray-200 justify-center aspect-square right-5")
endhttps://stackoverflow.com/questions/74622485
复制相似问题