module
Importance_2
Ruby on Rails latest stable (v7.1.3.2) - 0 notes

Action Cable Channel Callbacks

Action Cable Channel provides callback hooks that are invoked during the life cycle of a channel:

  • {before_subscribe}[rdoc-ref:ClassMethods#before_subscribe]

  • {after_subscribe}[rdoc-ref:ClassMethods#after_subscribe] (aliased as {on_subscribe}[rdoc-ref:ClassMethods#on_subscribe])

  • {before_unsubscribe}[rdoc-ref:ClassMethods#before_unsubscribe]

  • {after_unsubscribe}[rdoc-ref:ClassMethods#after_unsubscribe] (aliased as {on_unsubscribe}[rdoc-ref:ClassMethods#on_unsubscribe])

Example

class ChatChannel < ApplicationCable::Channel
  after_subscribe :send_welcome_message, unless: :subscription_rejected?
  after_subscribe :track_subscription

  private
    def send_welcome_message
      broadcast_to(...)
    end

    def track_subscription
      # ...
    end
end
Show files where this module is defined (1 file)
Register or log in to add new notes.