Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActionCable未接收数据_Ruby On Rails_Actioncable - Fatal编程技术网

Ruby on rails ActionCable未接收数据

Ruby on rails ActionCable未接收数据,ruby-on-rails,actioncable,Ruby On Rails,Actioncable,我使用ActionCable创建了以下内容,但无法接收正在广播的任何数据 评论频道: class CommentsChannel < ApplicationCable::Channel def subscribed comment = Comment.find(params[:id]) stream_for comment end end var cable = Cable.createConsumer('ws://localhost:3000/cable');

我使用ActionCable创建了以下内容,但无法接收正在广播的任何数据

评论频道

class CommentsChannel < ApplicationCable::Channel
  def subscribed
    comment = Comment.find(params[:id])
    stream_for comment
  end
end
var cable = Cable.createConsumer('ws://localhost:3000/cable');

var subscription = cable.subscriptions.create({
  channel: "CommentsChannel",
  id: 1
},{
  received: function(data) {
    console.log("Received data")
  }
});
它连接良好,我可以在日志中看到以下内容:

CommentsChannel is streaming from comments:Z2lkOi8vdHJhZGUtc2hvdy9FdmVudC8x
然后我向该流广播:

ActionCable.server.broadcast "comments:Z2lkOi8vdHJhZGUtc2hvdy9FdmVudC8x", { test: '123' }
问题是从未调用
received
函数。我做错什么了吗


注意:我正在使用
actioncable
npm包从BackboneJS应用程序进行连接。

config/cable.yml
中将电缆适配器从
async
更改为
redis
,为我解决了这个问题。不确定为什么
async
不起作用。

config/cable.yml
中将电缆适配器从
async
更改为
redis
,解决了这个问题。真棒,也有同样的问题。很高兴你发布了解决方案!对我有用。@Artem它对我没用。即使使用redis,广播也不起作用。服务器控制台显示:“[ActionCable]向room_频道广播:{:message=>“llllllllll”}”。但未调用接收到的函数。我尝试了asyn adapter和redis adapter。我不知道为什么它对您不起作用,但请确保redis服务器正在运行,并且redis主机设置在
cable.yml
中。我假设您从rails控制台进行广播?服务器和控制台正在使用独立的进程。您需要有一个集中式队列管理器。你需要使用redis,也为我解决了。真奇怪。谢谢@ArtemKalinchuk