从动作电缆文档中我读了这个例子来设置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类当前用户?