Live comments with model broadcasts + turbo_stream_from

13996
0

If a feature is fundamentally “live” (comments, activity), I reach for model broadcasts. Rails can broadcast Turbo Stream fragments on after_create_commit, and the UI subscribes with turbo_stream_from. The beauty is that it’s still server-rendered HTML: I broadcast a partial, not JSON. I scope streams carefully (usually per parent record) so you don’t leak updates across pages. This is a huge productivity win because you get realtime updates without building a bespoke ActionCable protocol. The downside is you need to be intentional about N+1 in your partials and about authorization: only subscribe users who should see the stream.