123456789_123456789_123456789_123456789_123456789_

Module: ActionCable::Channel::Broadcasting::ClassMethods

Relationships & Source Files
Defined in: actioncable/lib/action_cable/channel/broadcasting.rb

Instance Method Summary

Instance Method Details

#broadcast_to(model, message)

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

[ GitHub ]

  
# File 'actioncable/lib/action_cable/channel/broadcasting.rb', line 16

def broadcast_to(model, message)
  ActionCable.server.broadcast(broadcasting_for(model), message)
end

#broadcasting_for(model)

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.

[ GitHub ]

  
# File 'actioncable/lib/action_cable/channel/broadcasting.rb', line 26

def broadcasting_for(model)
  serialize_broadcasting([ channel_name, model ])
end