instance method broadcasts_to

Ruby on Rails 1.5.0

Since v1.3.3 Last seen in v2.0.23

Available in: v1.3.3 v1.4.0 v1.5.0 v2.0.23

Signature

broadcasts_to(stream, inserts_by: :append, target: broadcast_target_default, **rendering)

Configures the model to broadcast creates, updates, and destroys to a stream name derived at runtime by the stream symbol invocation. By default, the creates are appended to a dom id target name derived from the model’s plural name. The insertion can also be made to be a prepend by overwriting inserts_by and the target dom id overwritten by passing target. Examples:

class Message < ApplicationRecord
  belongs_to :board
  broadcasts_to :board
end

class Message < ApplicationRecord
  belongs_to :board
  broadcasts_to ->(message) { [ message.board, :messages ] }, inserts_by: :prepend, target: "board_messages"
end

class Message < ApplicationRecord
  belongs_to :board
  broadcasts_to ->(message) { [ message.board, :messages ] }, partial: "messages/custom_message"
end

Parameters

stream req
inserts_by key = :append
target key = broadcast_target_default
rendering keyrest
Source
# File app/models/concerns/turbo/broadcastable.rb, line 101
    def broadcasts_to(stream, inserts_by: :append, target: broadcast_target_default, **rendering)
      after_create_commit  -> { broadcast_action_later_to(stream.try(:call, self) || send(stream), action: inserts_by, target: target.try(:call, self) || target, **rendering) }
      after_update_commit  -> { broadcast_replace_later_to(stream.try(:call, self) || send(stream), **rendering) }
      after_destroy_commit -> { broadcast_remove_to(stream.try(:call, self) || send(stream)) }
    end

Defined in app/models/concerns/turbo/broadcastable.rb line 101 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Turbo::Broadcastable::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close