设置 Rails config.cache_classes=false 会导致 env['warden'].user 失败

问题描述 投票:0回答:1

我遇到了一个问题,在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

ruby-on-rails ruby actioncable
1个回答
0
投票

您可以将条件代码修改为:

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
© www.soinside.com 2019 - 2024. All rights reserved.