ruby - NameError 试图访问 Channel 中的 Connection 变量
问题描述
我有一个设置current_user
变量的连接:
class MyConnection < ActionCable::Connection::Base
identified_by :current_user
def connect
# snip - work to authenticate the user
self.current_user = user
end
end
根据文档,这应该使变量current_user
可用于相应的通道。文档说:
另请注意,在此示例中, current_user 可用,因为它被标记为连接上的标识属性。所有这些标识符都会在通道实例上自动创建一个同名的委托方法。
但是,当我尝试访问current_user
时MyChannel
:
class MyChannel < ActionCable::Channel::Base
def subscribed
subscription_name = "my_channel#{current_user.id}"
stream_from subscription_name
end
end
我得到一个NameError
:
NameError - undefined local variable or method `current_user' for #<MyChannel:0x00000000deadbeef>
我究竟做错了什么?
解决方案
推荐阅读
- reactjs - Typescript 和 React(使用 Gatsby 加载器):无法将图像作为模块导入
- c# - 无法在 C# 中打印出 powershell 脚本的输出
- laravel - Laravel 语言切换器,路由设置
- aspose - 如何获取 StackedColumn 图表中列的动态宽度
- html - Vue.JS 不读取 json 数据
- mysql - 如何在 SQL 脚本中传递预定义的值?
- c# - wpf界面元素被ocx控件覆盖
- postgresql - Activemq postgresql 在 activemq_msgs 表中将消息详细信息和内容记录为 JSON
- c - 如何在 x86_64 中使用 clang-8 的“影子调用堆栈”功能?
- javascript - iOS 通用链接在 Twitter 应用程序中不起作用,但 android 应用程序链接有效