title: How do you stream a broadcast to a specific user in Rails 5 with ActionCable?
body: <p>I have 2 user types in my application (worker and company). Both user types are created with Devise. I'm currently trying to send a notification to a specific company with ActionCable. </p>
  
  <p>My main problem is that when I send a notification every single company that's signed in receives it. I get that I'm supposed to include the company id in the stream name in some way, but I haven't had any luck so far.</p>
  
  <p>I've included the working code that sends notifications to all companies below:</p>
  
  <p><strong>notifications_channel.rb</strong></p>
  
  <pre><code>class NotificationsChannel &lt; ApplicationCable::Channel
    def subscribed
      stream_from "notifications_channel"
    end
  
    def unsubscribed
      # Any cleanup needed when channel is unsubscribed
    end
  end
  </code></pre>
  
  <p><strong>connection.rb</strong></p>
  
  <pre><code>module ApplicationCable
    class Connection &lt; ActionCable::Connection::Base
    end
  end
  </code></pre>
  
  <p><strong>Call to the broadcast</strong></p>
  
  <pre><code>ActionCable.server.broadcast 'notifications_channel', { 'My data' }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I log the status of the notification with javascript:</p>
  
  <p><strong>notifications.js</strong></p>
  
  <pre><code>App.notifications = App.cable.subscriptions.create("NotificationsChannel", {
    connected: function() {
      console.log("connected");
    };
  
    disconnected: function() {
      console.log("disconnected");
    };
  
    received: function(data) {
      console.log("recieved");
    };
  });
  </code></pre>