Skip to content

Instantly share code, notes, and snippets.

@jch
Created June 8, 2012 23:38
Show Gist options
  • Save jch/2898697 to your computer and use it in GitHub Desktop.
Save jch/2898697 to your computer and use it in GitHub Desktop.
# A Sidekiq background job worker tha knows how to render Rails views
# Don't worry, I *think* I know what I'm doing ;)
class RenderWorker < AbstractController::Base
include AbstractController::Rendering
include AbstractController::Logger # dependency from actionview calling logging
include Rails.application.routes.url_helpers
include Sidekiq::Worker
append_view_path "#{Rails.root}/app/views" # from AbstractController::ViewPaths
def perform
@somevar = "somevalue" # variables and route helpers available in view
html = render :action => 'foo'
Pusher['some_channel'].trigger('some_event', html)
end
end
w = RenderWorker.new
w.perform
@natesire
Copy link

how did this code work out for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment