Wicked_pdf: Generate attachment in Sidekiq

Created on 12 Nov 2018  路  1Comment  路  Source: mileszs/wicked_pdf

Hi,

I've created a layout which can take several seconds until it's renderd.
So I moved the generation into a sidekiq worker to run in a background job.

The issue is now that render_to_string returns a NoMethodError.
I've tried several includes but nothing works.

Did anybody solved the problem?

WARN: NoMethodError: undefined method `render_to_string' for #

class PdfWorker
  include Sidekiq::Worker
  sidekiq_options queue: 'files', retry: false, backtrace: true

  def perform(business_id, user_id, places)
    file = WickedPdf.new.pdf_from_string(
        render_to_string template: '/path_to_tmeplate/template.pdf', disposition: 'attachment', layout: 'application.print', lowquality: false, image_quality: 100,
                         margin: {top: 10, bottom: 0, left: 20, right: 20}
    )

    FilemailerMailer.file(file).deliver_now!
  end
end

Most helpful comment

Solved

ApplicationController.new.render_to_string

>All comments

Solved

ApplicationController.new.render_to_string
Was this page helpful?
0 / 5 - 0 ratings

Related issues

VladFarion picture VladFarion  路  4Comments

lsarni picture lsarni  路  5Comments

BlakeWard picture BlakeWard  路  3Comments

dgdosen picture dgdosen  路  5Comments

douglasep picture douglasep  路  4Comments