I’m playing around with Turbo Streams and I feel like I’m not understanding when to use
respond_to do |format|
format.turbo_stream
end
Can someone explain when you would want to use this?
If I’m in my update
method in my users_controller
and use it like this
format.turbo_stream { render turbo_stream: turbo_stream.replace(@user, partial: "users/user_card", locals: { user: @user}) }
It replaces. the user_card
with the correct dom_id, but it only does it locally and doesn’t broadcast anything unless I also have
after_update_commit { broadcast_replace_to "admin_user_list", partial: "users/user_card" }
in my user.rb
.
If I have the after_update_commit
but don’t have the format.turbo_stream
in my controller, and instead have just the standard format.html
, the user_card
with the correct dom_id gets replaced and it is broadcasted to the admin_user_list
As I said, I feel like I’m missing something.
Related, One issue I am foreseeing is that if want a different partial to be rendered for a model based on some condition, I don’t see how I will be able to do it and still have it be broadcastable.
Can anyone explain? Thank you!