You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Turbo stream doesn't play nicely with current_user reference in partial. This is because this variable is not defined in the context of the broadcast as the same partial is rendered to every subscribed streams.
This prevent to use policies in these views are the rely on current_user to work.
A workaround could be to render an intermediate partial that would asynchronously request the endpoint in the context of each user with turbo_frame_tag.
Pros:
we can safely use current_user and policies on the partial
Cons:
need an intermediate partial to tweak it
depending on the number of user subscribed to the stream it would make a server request for any of them and could be very heavy for a server
Turbo stream doesn't play nicely with
current_user
reference in partial. This is because this variable is not defined in the context of the broadcast as the same partial is rendered to every subscribed streams.This prevent to use policies in these views are the rely on
current_user
to work.A workaround could be to render an intermediate partial that would asynchronously request the endpoint in the context of each user with
turbo_frame_tag
.Pros:
current_user
and policies on the partialCons:
Implementation example
Reference blog article: https://www.colby.so/posts/conditional-rendering-with-turbo-stream-broadcasts
The text was updated successfully, but these errors were encountered: