简体   繁体   English

Ruby on Rails操作电缆:扩展ApplicationCable Connection类

[英]Ruby on Rails Action Cable: Extending ApplicationCable Connection class

I was wondering if it was possible to extend the action cable connect class so that I can create other 'base controllers' that inherit from the main connection class. 我想知道是否可以扩展动作电缆连接类,以便我可以创建从主连接类继承的其他“基本控制器”。

I basically want to do different authentication methods for different streams, and all I am trying to do is essentially do what you do for the application controller where you can have other base controllers that inherit from the application controller. 我基本上想对不同的流执行不同的身份验证方法,而我要做的基本上就是为应用程序控制器执行操作,在此可以拥有从应用程序控制器继承的其他基本控制器。

I couldn't find a way to specify different Connection classes for different channels. 我找不到为不同频道指定不同Connection类的方法。 I solved this by setting an instance variable and attr_reader in the Connection class specifying if the user logged in or not (I have authenticated and unauthenticated channels). 我通过在Connection类中设置实例变量和attr_reader来解决此问题,该变量指定用户是否登录(我具有经过身份验证和未经身份验证的通道)。 Then from the Channel I would verify the login with connection.did_login and raise an exception. 然后从Channel我将使用connection.did_login验证登录并引发异常。 Not the prettiest but it seems to work. 不是最漂亮,但它似乎可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM