Ask A Question

Notifications

You’re not receiving notifications from this thread.

How can I have two connections in ActionCable?

Colton Hagan asked in Rails

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.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,842+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.