stream_from, we're going to use the
broadcast_tomethod, which requires that you pass a resource to it.
broadcast_tomagic that we discuss on this page.
HelensChannelknows what a
Postis or not; it's just joining strings together.
broadcasting_foris not bad, but
broadcast_tois more powerful and presents more interesting creative possibilities.
broadcastmake it easy to develop reactive interfaces with Rails.
broadcast_toactually unlock new feature and UX design possibilities.
has_manyrelationship or even an integer array attribute
current_userpattern so often that we can almost forget that it's a resource. You know what doesn't forget? CableReady.
rails g channel usersto create a UsersChannel.
current_userreference from your Connection class, no
current_userfrom anywhere in your app.
broadcast_toallows the developer to queue up all required interface updates on their respective Channels before delivering them with a single, brutal command.
idmetadata in your views. For some applications, slugs are a good approach. Other times, Signed Global IDs (aka sgid) are a powerful choice because you cannot reverse engineer the model or id from the resulting string. You can even generate sgids which are use-limited.
sgidinstead of an
find, just hand the parameter off to
#prepended to the
stream_formultiple resources in one Channel, making use of ternary logic operators and any other decision making structure that might be applicable to your application. After all, if you have instantiated a model instance, you've ready used a substantial amount of logic that is hidden away behind syntactic magic.
broadcast_tois designed to enable shared experiences around resources. A resource that doesn't exist yet is fundamentally difficult to collaborate on. Yet, when you create an empty Google Doc and share editing rights, the document already exists in every meaningful way. If we want a similar outcome, we have to find creative ways to operate on resources that aren't persisted and might not pass validations.
paramarrives, establish the subscription and then create the model instance you need. Send the id of that model back to the client:
idvalue, we create a temporary UUIDv4 for the new resource and send that to the server. When the server sends us an integer back, we can set the
idValuebefore unsubscribing from the channel and forcing another controller
connectmethod. After all, it really is just a method:
cable_ready[HelensChannel]are separate operation queues
broadcastcan only work with string-based stream identifiers
broadcast_tocan only work with constant-based stream identifiers