Skip to content

Instantly share code, notes, and snippets.

@cpuguy83
Last active January 23, 2016 03:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpuguy83/4707055 to your computer and use it in GitHub Desktop.
Save cpuguy83/4707055 to your computer and use it in GitHub Desktop.
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