Rails 7.1: implementing generating PDF reports using Wicked PDF and ActionCable
I'm stuck on something that should probably be simple. I'm working with a frustrating scenario while trying to generate PDF reports for my Rails 7.1 application using Wicked PDF in conjunction with ActionCable. I have set up everything according to the documentation, but when I try to render a PDF from a background job triggered via ActionCable, I get the behavior: `WickedPdf::behavior: PDF could not be generated.` I'm using the following code in my background job: ```ruby class PdfReportJob < ApplicationJob queue_as :default def perform(report_id) report = Report.find(report_id) WickedPdf.new.pdf_from_string( ApplicationController.render( template: 'reports/show.pdf.erb', locals: { report: report } ), disposition: 'attachment' ) end end ``` I also have the following in my `reports_controller.rb`: ```ruby class ReportsController < ApplicationController def show @report = Report.find(params[:id]) ActionCable.server.broadcast 'report_channel', pdf_url: pdf_report_path(@report) end end ``` The PDF generation works perfectly when I call it synchronously from the controller, but as soon as I try to execute it from the background job, it fails. I've checked that the `wkhtmltopdf` binary is correctly set in the `initializers/wicked_pdf.rb` and is accessible. I've tried adding `puts` statements in the job to debug but they don't output anything useful. Additionally, my Rails logs show no specific errors related to PDF generation, just the generic behavior message. Has anyone encountered this scenario before, or does anyone have suggestions on how to successfully generate PDFs from a background job in this setup? The stack includes Ruby and several other technologies. Is there a simpler solution I'm overlooking?