Rails5 ActionCable включает метод current_user из SessionsHelper

Я хочу получить доступ к моему методу current_user, который определен в SessionsHelper. Как я могу включить или потребовать его для класса подключения ApplicationCable?

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

дает мне

There was an exception - NoMethodError(undefined method `name' for nil:NilClass)

Эквивалент ApplicationController. Я включил SessionHelper в каналы / application_cable / connection.rb

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

но не работает.


person Stef Hej    schedule 29.04.2016    source источник


Ответы (1)


Как вы можете видеть в примечаниях официальной документации, кабель не может получить доступ к сеансу. В этой статье, цитируемой в примечаниях, вы можете найти способ использования файлов cookie для управление аутентификацией

person rick    schedule 29.04.2016