Action cable: How to broadcast the chat messages only the specific chat room in Rails 5?

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Action cable: How to broadcast the chat messages only the specific chat room in Rails 5?

Aqib Hameed

I currently have a Rails 5 application acting as my back-end,we can call this the "Core." I also have another Angular 1.6.4 application acting as my front-end, which is serving up Angular client side,And integrate with backed-end application through angular-actionable we can call this the "Front". These are two completely separate applications with completely different domains.

Basically, I am trying to integrate Action Cable through the Core and have it talk to the Front. I'm using this service here for the Front:  enter link description here. As far as the Core, that's just basic Action Cable set up.

I have a list of chat rooms on admin side. 

Problem: I sent message from client side but it broadcast message to all the chat rooms in admin side.I try to give the specific path of chat room in stream but still it broadcast message to all chat rooms.

I want to broadcast the message to specific chat room.How i give specific path to broadcast message to specific chat room ????



class ChatChannel < ApplicationCable::Channel
   def subscribed
      stream_from stream_name
   def unsubscribed

   def receive(data)
       ActionCable.server.broadcast stream_name,  data.fetch('message')


   def stream_name

   def chat_id
chatCtrl.js (ActionCableConfig){
   ActionCableConfig.debug = true;
   ActionCableConfig.wsUri= "ws://localhost:3000/cable";
app.controller('chatCtrl', ['$scope', 'ActionCableChannel',
function($scope, ActionCableChannel) {

  var consumer = new ActionCableChannel("ChatChannel", { chat: 'localhost:3000/#!/chat/1'});
  var callback = function(message) {
    $scope.sendToMyChannel = function(message){
    $scope.$on("$destroy", function(){
      consumer.unsubscribe().then(function(){ $scope.sendToMyChannel = undefined; });

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit
For more options, visit