跳至内容 跳至搜索
方法
B

实例公共方法

broadcast_to(model, message)

将一个哈希广播到此频道中model的唯一广播。

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

broadcasting_for(model)

返回此频道中model的唯一广播标识符。

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

您可以将任何对象作为目标(例如,Active Record 模型),它将在后台被序列化为字符串。

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