Ruby on Rails
Monday, May 6, 2019
Thanks for the tips
-- I got it working making sure that at the client I put the send line in the connect function so it didn't try to send before connecting, and I passed in a dictionary object.
app/assets/javascripts/theawpchan.js
App.awpchan.send({message: 'This is a cool chat app.'});
App.awpchan = App.cable.subscriptions.create("AwpchanChannel", {
connected: function() {
App.awpchan.send({message: 'This is a cool chat app.'});
},
disconnected: function() {},
received: function(data) {
return alert(data);
}
});
// http://js2.coffee/
And I added the receive method at the server side..
app/channels/awpchan_channel.rb
class AwpchanChannel < ApplicationCable::Channel
def subscribed
stream_from "abcdstrm"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
def receive(data)
puts data["message"]
end
end
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3cc4c9bf-c54b-4ca5-bb64-3f36da22837a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment