All threads / Could we get a video on passing Devise current_user (or general user roles) into a Turbo partial?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Could we get a video on passing Devise current_user (or general user roles) into a Turbo partial?

Marc Jaramillo asked in General

Hi Chris,

I was just wondering if there is any possibility of getting a video or some tips on including Devise current_user data or user roles inside a turbo stream - specifically to show/hide edit and delete links? I've gotten a threaded comment feature working after going through the Real-Time Nested Comments videos, but I can't get the edit/delete links working. In this post, DHH says "Partials used for turbo streaming have to be free of global references, as they’re rendered by the ApplicationRenderer, not within the context of a specific request" and in this closed issue he says "You'll need to make a partial that's not dependent on global state like this to work. You can use client-side show/hide using a stimulus controller instead". I've tried to find ideas on work arounds, and I've seen a few workarounds: this one with CSS and this one using local variables. I've tried adapting both of these approaches to my project, but no dice.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 46,687+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.