Rails5 ActionCable 包括来自 SessionsHelper 的 current_user 方法
Rails5 ActionCable include current_user method from SessionsHelper
我想访问 current_user 方法,该方法在 SessionsHelper 中定义。我如何 include 或要求 ApplicationCable 连接 class?
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)
相当于我在channels/application_cable/connection.rb
中包含SessionHelper的ApplicationController
module ApplicationCable
class Connection < ActionCable::Connection::Base
include SessionsHelper
identified_by :current_user
# (..)
end
end
但不起作用。
我想访问 current_user 方法,该方法在 SessionsHelper 中定义。我如何 include 或要求 ApplicationCable 连接 class?
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)
相当于我在channels/application_cable/connection.rb
中包含SessionHelper的ApplicationControllermodule ApplicationCable
class Connection < ActionCable::Connection::Base
include SessionsHelper
identified_by :current_user
# (..)
end
end
但不起作用。