Skip to content

Instantly share code, notes, and snippets.

View salmanasiddiqui's full-sized avatar

Salman Siddiqui salmanasiddiqui

  • Canada
  • 04:26 (UTC -04:00)
View GitHub Profile

Keybase proof

I hereby claim:

  • I am salmanasiddiqui on github.
  • I am salmanasiddiqui (https://keybase.io/salmanasiddiqui) on keybase.
  • I have a public key ASB3U7pxY0IgFNlVHuYdDQ5Xp73D3WyeGA0vjZiCSU-DDwo

To claim this, I am signing this object:

@salmanasiddiqui
salmanasiddiqui / notifications_controller.rb
Last active March 20, 2024 18:58
Right way to use Rails SSE for live notification
class NotificationsController < ApplicationController
def notify_me
# Rails reserve a db connection from connection pool for each request, lets put it back into connection pool.
ActiveRecord::Base.clear_active_connections!
# required header
response.headers['Content-Type'] = 'text/event-stream'
sse = ActionController::Live::SSE.new(response.stream)