我正在尝试将ActionCable实现到Rails 5.2.1应用程序。我添加了congif / cable.yml文件,因为它丢失了,并且生成了频道,但是我尝试使用commant从Rails控制台广播消息
ActionCable.server.broadcast 'comments:1', { asd: true }
它返回我错误消息:
undefined method `debug' for nil:NilClass
channels / comments_channel.rb
class CommentsChannel < ApplicationCable::Channel
def subscribed
stream_from "comments:1"
end
def unsubscribed
stop_all_streams
end
end
assets / javascripts / channels / comments.js
App.comments = App.cable.subscriptions.create("CommentsChannel", {
connected: function() {
// Called when the subscription is ready for use on the server
},
disconnected: function() {
// Called when the subscription has been terminated by the server
},
received: function(data) {
console.log(data)
}
});
config / cable.yml
development:
adapter: redis
url: redis://localhost:6379/1
test:
adapter: async
production:
adapter: redis
url: redis://localhost:6379/1