Created
July 26, 2017 23:07
-
-
Save scottdomes/8987595f8a9feaa6767f87462203d3b3 to your computer and use it in GitHub Desktop.
Note channel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NotesChannel < ApplicationCable::Channel | |
def subscribed | |
# stream_from "some_channel" | |
stream_from 'notes' | |
end | |
def unsubscribed | |
# Any cleanup needed when channel is unsubscribed | |
end | |
def receive(data) | |
note = Note.find(data["id"]) | |
note.update!(text: data["text"]) | |
ActionCable.server.broadcast('notes', data) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment