Skip to content

Instantly share code, notes, and snippets.

@cpuguy83

cpuguy83/base_pusher.rb

Last active Jan 23, 2016
Embed
What would you like to do?
Server Push based controller
class BasePusher < AbstractController::Base
include AbstractController::Logger
include AbstractController::Rendering
include AbstractController::Layouts
include AbstractController::Helpers
include AbstractController::Translation
include AbstractController::AssetPaths
include AbstractController::Callbacks
include Rails.application.routes.url_helpers if defined? Rails
# Needed this because my partials use caching
include ActionView::Helpers::CacheHelper if defined? ActionView
include ActionController::Caching::Fragments if defined? ActionController
helper ApplicationHelper
self.view_paths = "app/views"
# Haven't gotten the requirements down for actually caching just yet, so disabling
# But this needs to be set so we don't get exceptions on when the cache method is called from the view
def perform_caching
false
end
def controller_path
@controller_path ||= self.class.to_s.gsub(/Pusher$/, '').underscore
end
end
class FooObject < ActiveRecord::Base
after_save :push_to_client
private
def push_to_client
FooBjectsPusher.new.foo_action
end
end
FooObjectsPusher < BasePusher
# define actions
def foo_action
# format content and push
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment