我希望能够访问 SessionsHelper 中定义的 current_user 方法。我如何包含或要求 ApplicationCable 连接类?
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
if current_user
self.current_user = current_user
logger.add_tags current_user.name
end
end
end
end
给了我
There was an exception - NoMethodError(undefined method `name' for nil:NilClass)
相当于ApplicationController我包含在channels / application_cable / connection.rb中的SessionHelper
module ApplicationCable
class Connection < ActionCable::Connection::Base
include SessionsHelper
identified_by :current_user
# (..)
end
end
但不起作用。