我遇到了一个问题,在development.rb中设置
config.cache_classes=false
会导致以下方法find_verified_user
无法执行。
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user.id
end
protected
def find_verified_user # this checks whether a user is authenticated with devise
if verified_user = env['warden'].user
verified_user
else
reject_unauthorized_connection
end
end
end
end
您可以将条件代码修改为:
def find_verified_user # this checks whether a user is authenticated with devise
if verified_user == env['warden'].user
verified_user
else
reject_unauthorized_connection
end
end