Skip to main content

How can I have two connections in ActionCable?

Rails • Asked by Colton Hagan

I have Notifications Channel and a Pings Channel. Notifications are identified by my devise modal Agents. But my Pings Channel needs to be identified by my other devise modal, Users. Heres some sudocode to explain better. This would be ideal:

connection.rb
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_agent
        identified_by :current_user

    def connect
      self.current_agent = find_verfied_agent
            self.current_user = find_verfied_user
    end

    protected

    def find_verfied_agent
      if current_agent = env['warden'].user
        current_agent
      else
        reject_unauthorized_connection
      end
    end

        def find_verfied_user
      if current_user = env['warden'].user
        current_user
      else
        reject_unauthorized_connection
      end
    end
  end
end

After searching I found this on stack overflow:
https://stackoverflow.com/questions/41672673/multiple-connections-in-actioncable

So basically the same question.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.