Ho creato quanto segue utilizzando ActionCable ma non in grado di ricevere alcun dato che viene trasmesso.ActionCable Not Receiving Data
Commenti Canale:
class CommentsChannel < ApplicationCable::Channel
def subscribed
comment = Comment.find(params[:id])
stream_for comment
end
end
JavaScript:
var cable = Cable.createConsumer('ws://localhost:3000/cable');
var subscription = cable.subscriptions.create({
channel: "CommentsChannel",
id: 1
},{
received: function(data) {
console.log("Received data")
}
});
Si collega benissimo e posso vedere il seguente nei registri:
CommentsChannel is streaming from comments:Z2lkOi8vdHJhZGUtc2hvdy9FdmVudC8x
ho poi trasmesso a tha t flusso:
ActionCable.server.broadcast "comments:Z2lkOi8vdHJhZGUtc2hvdy9FdmVudC8x", { test: '123' }
Il problema è che la funzione received
non viene mai chiamato. Sto facendo qualcosa di sbagliato?
Nota: sto utilizzando il pacchetto n. actioncable
per connettersi da un'applicazione BackboneJS.
La modifica dell'adattatore del cavo da 'async' a' redis' in 'config/cable.yml' è stata corretta. –