【发布时间】:2020-12-14 19:40:44
【问题描述】:
我需要为应用程序添加对多个模型(带有用户的表)的支持。总的来说,除了 ApplicationCable 之外,一切都很顺利。
该应用程序有这个代码:
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end
protected
def find_verified_user
if verified_user = env['warden'].user
verified_user
else
reject_unauthorized_connection
end
end
end
end
这段代码很受欢迎。它存在于许多来源中。
但它不适用于需要多个模型的情况。前端的连接被切断,原因是:
未经授权的连接尝试被拒绝
UPD:
我意识到我可以使用明确的指示:
env['warden'].user(:admin)
但现在我不明白如何为 ApplicationCable 连接自动确定这一点。
你能告诉我如何解决这个问题吗?
【问题讨论】:
标签: ruby-on-rails devise ruby-on-rails-6 actioncable