如何从ActionCable :: Connection :: Base中检索会话存储

时间:2018-01-11 11:46:42

标签: ruby-on-rails actioncable

从动作电缆文档中我读了这个例子来设置current_user:

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

  def connect
    self.current_user = find_verified_user
  end

  private
    def find_verified_user
      if verified_user = User.find_by(id: cookies.signed[:user_id])
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end

我没有设置user_id cookie,因为对cas服务器进行了身份验证,并且它将会话存储在Active Record中。 如何告诉Connection类当前用户?

1 个答案:

答案 0 :(得分:0)

您需要强制加载会话。点击此链接(为我工作):How force that session is loaded?