Ruby on rails Rails5 ActionCable包含来自SessionHelper的当前用户方法

Ruby on rails Rails5 ActionCable包含来自SessionHelper的当前用户方法,ruby-on-rails,ruby-on-rails-5,actioncable,Ruby On Rails,Ruby On Rails 5,Actioncable,我想访问我的当前用户方法,该方法在会话助手中定义。我如何将包含在应用程序表连接类中或要求它 module ApplicationCable class Connection < ActionCable::Connection::Base identified_by :current_user def connect if current_user self.current_user = current_user logg

我想访问我的当前用户方法,该方法在会话助手中定义。我如何将包含在应用程序表连接类中或要求它

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      if current_user
        self.current_user = current_user  
        logger.add_tags current_user.name
      end
    end
  end
end
相当于ApplicationController I在channels/application\u cable/connection.rb中包含的会话助手

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    include SessionsHelper
    identified_by :current_user
    # (..)
  end
end
模块应用程序表
类连接
但不起作用。

正如您在官方文档中看到的,该电缆无法访问会话。在注释中引用的这篇文章中,您可以找到一种使用cookie来管理athentication的方法

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    include SessionsHelper
    identified_by :current_user
    # (..)
  end
end