6

I'm trying to get actioncable working, but when I send out ActionCable.server.broadcast "discussion", {asdf: true} in rails console it always returns 0.

I have the redis server running and configured in cable.yml.

Any advice as to what I'm doing wrong would be apperciated.

Rails

DiscussionChannel is transmitting the subscription confirmation
DiscussionChannel is streaming from discussion_channel

Rails Console

Running via Spring preloader in process 17262
Loading development environment (Rails 5.2.2)
2.6.0 :001 > ActionCable.server.broadcast "discussion", {asdf: true}
[ActionCable] Broadcasting to discussion: {:asdf=>true}
 => 0 

discussion_channel.rb

class DiscussionChannel < ApplicationCable::Channel
  def subscribed
     stream_from "discussion_channel"
  end

  def unsubscribed
  end

end

discussion.coffee

App.discussion = App.cable.subscriptions.create "DiscussionChannel",
  connected: ->

  disconnected: ->

  received: (data) ->
     console.log(data)
  • Does this answer your question? [ActionCable.server.broadcast from the console](https://stackoverflow.com/questions/35176934/actioncable-server-broadcast-from-the-console) – David Metta Sep 04 '21 at 09:56

1 Answers1

0

This question is a possible duplicate of this and this.

Basically the default behaviour for ActionCable in development mode is to use the async adapter, which operates within the same process only. Since your rails console and rails server run in different processes, calling ActionCable::Server#broadcast in the console will not work by default. For inter-process broadcasting, you will need to change the configuration in config/cable.yml to use Redis in development as well.