略過至內容 略過至搜尋

Action Cable Connection Callbacks

在將命令傳送至客戶端時會呼叫 before_commandafter_commandaround_command 回呼,例如在訂閱、取消訂閱或執行動作時。

範例

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :user

    around_command :set_current_account

    private

    def set_current_account
      # Now all channels could use Current.account
      Current.set(account: user.account) { yield }
    end
  end
end
命名空間
包含的模組