So I have an issue, I want to render current_user specific partials to my turbo stream. In my use case I have an instant messaging app, and when a user writes a new message I would like to broadcast that message to all the users within that chat. My issue is that message partial has user specific buttons with user specific permissions in it, aka edit and delete, which should only be accessible to the message creator and admin users. The issue I run into is that when broadcasting a partial to a stream I don't know how to attribute the current_user variable (using devise) within that partial to the user being broadcast to. At the moment I have a hacked solution using a stimulus connect() callback, but it is my no means ideal. Can anyone help me out? I am sure there must be a more sophisticated and simpler way of doing this that doesn't involve every user receiving the message to trigger there own request.
Any help would be greatly appreciated,
Thanks, Lenny
Top comments (2)
Hi!
Variant 1:
Controller
github.com/secretpray/turbochat/bl...
Views
github.com/secretpray/turbochat/bl...
Stimulus
github.com/secretpray/turbochat/bl...
Variant 2:
Individual Broadcasts channels & partial:
Model
github.com/secretpray/Real-Time-Co...
Views
github.com/secretpray/Real-Time-Co...
github.com/secretpray/Real-Time-Co...
github.com/secretpray/Real-Time-Co...
Autorize:
views
github.com/secretpray/Real-Time-Co...
stimulus
github.com/secretpray/Real-Time-Co...
@secretpray has it all figured out 💯