简体   繁体   中英

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. 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). Then from the Channel I would verify the login with connection.did_login and raise an exception. Not the prettiest but it seems to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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