跳至內容 跳至搜尋
方法
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