1
我想訪問我的current_user方法,該方法在SessionsHelper中定義。我如何包括或要求它爲ApplicationCable連接類?Rails5 ActionCable包含來自SessionsHelper的current_user方法
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中我包括的SessionHelper在渠道/ application_cable/connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
include SessionsHelper
identified_by :current_user
# (..)
end
end
,但不起作用。