Skip to content

Instantly share code, notes, and snippets.

@costa
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save costa/bf81827963b5f6987c4f to your computer and use it in GitHub Desktop.

Select an option

Save costa/bf81827963b5f6987c4f to your computer and use it in GitHub Desktop.
Rails model notification concern employing Pusher: app/models/concerns
module Notification
extend ActiveSupport::Concern
included do
after_create { notify 'created' }
after_update { notify 'updated' }
after_destroy { notify 'destroyed' }
class << self
def notify_async(channel, event, json)
Pusher[channel].trigger event, json
end
handle_asynchronously :notify_async, :priority => REALTIME_NOTIFICATIONS_PRIORITY
end
end
private
def notify(event)
self.class.notify_async pusher_channel, event, as_json if pusher_channel
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment