I have this html setup:
<%= turbo_stream_from "articles_stream" %>
<div id="articles">
<div class="article"></div>
<div class="article"></div>
<div class="article"></div>
<div class="article"></div>
</div>
I want to stream content to the last article
in the #articles
element.
document.querySelector("#articles .article:last-child")
I have tried this:
broadcast_append_to(
"articles_stream",
target: "#articles .article"
)
Doesn’t work.
I see that in turbo 7 there is a new targets
attribute that supports css selector. So I tried:
broadcast_append_to(
"articles_stream",
targets: "#articles .article"
)
Also doesn’t work.
I don’t see any documentation about targets
in the turbo-rails documentation.
What is the way?
broadcast_append_to(
"articles_stream",
target: nil,
targets: "#articles .article"
)
There is an open PR to solve this in a more elegant way.