'Use current_user in hotwire partial

Hi I started using hotwire in rails app (currently I am working on adding comments) and I found that partials used for turbo streaming are free of global references and I would like to use current_user in partial but then i had to reload page to add a comment. Did any of you have a similar problem and could you give me a hint how to do that?



Solution 1:[1]

save the current_user_id in cookies in session_controller

cookies[:current_user_id] = current_user.id

enter image description here

in application_controller

def devise_current_user
 @devise_current_user ||= warden.authenticate(scope: :user)
end

def current_user
  devise_current_user
  rescue
    User.find(cookies[:current_user_id])
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mueez Afzal