Skip to content

Instantly share code, notes, and snippets.

@kivanio
Forked from jch/render_worker.rb
Created April 2, 2014 21:35
Show Gist options
  • Save kivanio/9943673 to your computer and use it in GitHub Desktop.
Save kivanio/9943673 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment