module ActionCable::Channel::Broadcasting::ClassMethods

Public Instance Methods

broadcast_to(model, message) Show source
# File actioncable/lib/action_cable/channel/broadcasting.rb, line 14
def broadcast_to(model, message)
  ActionCable.server.broadcast(broadcasting_for(model), message)
end

Broadcast a hash to a unique broadcasting for this model in this channel.

broadcasting_for(model) Show source
# File actioncable/lib/action_cable/channel/broadcasting.rb, line 24
def broadcasting_for(model)
  serialize_broadcasting([ channel_name, model ])
end

Returns a unique broadcasting identifier for this model in this channel:

CommentsChannel.broadcasting_for("all") # => "comments:all"

You can pass any object as a target (e.g. Active Record model), and it would be serialized into a string under the hood.

© 2004–2019 David Heinemeier Hansson
Licensed under the MIT License.