Hey Mike, thx for your efforts and a nice lesson!
Got a question tho. Imagine we need to broadcast from the controller action, not from the model with a proc.
Here's how I do it:
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.prepend(:tweets, partial: "tweets/tweet",
locals: { tweet: @tweet })
end
format.html { redirect_to tweets_url, notice: 'Tweet was successfully created.' }
format.json { render :show, status: :created, location: @tweet }
end
This approach works pretty much the same, but the new tweets don't appear in another browser tab! New tweet does show up on the author's tab, but on any other tab/browser/device -- it simply doesn't.
Frankly, I didn't really spend much time digging in the docs, did I miss anything maybe?
Best.
turbo_stream is like an AJAX update to the user who made that request. Personally I'm going to stay far away from it & stick with using broadcast_to with my model.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey Mike, thx for your efforts and a nice lesson!
Got a question tho. Imagine we need to broadcast from the controller action, not from the model with a proc.
Here's how I do it:
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.prepend(:tweets, partial: "tweets/tweet",
locals: { tweet: @tweet })
end
format.html { redirect_to tweets_url, notice: 'Tweet was successfully created.' }
format.json { render :show, status: :created, location: @tweet }
end
This approach works pretty much the same, but the new tweets don't appear in another browser tab! New tweet does show up on the author's tab, but on any other tab/browser/device -- it simply doesn't.
Frankly, I didn't really spend much time digging in the docs, did I miss anything maybe?
Best.
turbo_stream
is like an AJAX update to the user who made that request. Personally I'm going to stay far away from it & stick with usingbroadcast_to
with my model.