Skip to content

Instantly share code, notes, and snippets.

@jackrg
Created January 24, 2014 17:58
Show Gist options
  • Save jackrg/8602584 to your computer and use it in GitHub Desktop.
Save jackrg/8602584 to your computer and use it in GitHub Desktop.
class SalesReportWorker < ApplicationController
include Sidekiq::Worker
sidekiq_options backtrace: true, retry: false
self.view_paths = "app/views" # Where to look for view templates
def perform(request_ident, params)
@_response = ActionDispatch::Response.new # Needed to avoid "ActionController::RackDelegation#content_type
# delegated to @_response.content_type, but @_response is nil" error
...
html = render template: 'sales_reports/show.js.erb'
...
end
...
end
@jackrg
Copy link
Author

jackrg commented Jan 24, 2014

This gist shows how to use the Rails rendering engine within a Sidekiq worker.

@eduardohertz
Copy link

Hello, Jack. Did you try this approach on Rails 4.1? I'm trying to do this, but I'm getting the following error:

Failure/Error: subject.export
     ActionView::Template::Error:
       undefined method 'host' for nil:NilClass

Do you have any idea? Rails expect to find a request object that responds to host method. The backtrace: actionpack-4.1.9/lib/action_controller/metal/url_for.rb:27:inurl_options'`

Thanks.

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