mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.54k stars 647 forks source link

ActionView::Template::Error uninitialized constant WickedPdf::WickedPdfHelper::Assets::SprocketsEnvironment::Sprockets #1102

Open DanTaiko opened 9 months ago

DanTaiko commented 9 months ago

The v2.7.0 of wicked_pdf seems not to be fully incompatible with Rails 7. Rails 7.0 makes Sprockets an optional dependency. We don't use Sprockets in our Rails 7.1 app and updating wicked_pdf to v2.7.0 make us a bit of trouble.

There is a addition to _WickedPdf::WickedPdfHelper::Assets#readasset that makes the difference: asset = find_asset(source)

Downgrading _wickedpdf back to v2.6.3 restored the functionality.

dmrwebdev commented 8 months ago

Our Rails 7.1 application just experienced the same constant error when dependabot updated our application to v2.8.0 from v.2.7.0. We are not using sprockets either.

fblupi commented 8 months ago

Same problem in an application with Rails 6.1.7.7 deployed in Heroku. Downgrading from v2.8.0 to v2.7.0 made the trick.

blocknotes commented 3 months ago

Same error in one of our projects while upgrading to the version 2.8.0

Perhaps it could be related to: https://github.com/mileszs/wicked_pdf/issues/1117

laurajaime commented 2 months ago

Same problem with 2.8.0 here!

attenzione commented 2 months ago

I had CSS and image references in a PDF, and I resolved the issue by embedding them as base64:

= stylesheet_link_tag(asset_base64_for('pdf.css'))
= image_tag(asset_base64_for('invoices/logo.png'))

asset_base64_for depends on your implementation of serving assets. Simplified code is below:

def asset_base64_for(name)
  content_type = MIME::Types.type_for(name).first.content_type

  path = asset_physical_path(name) # this method returns location of the file
  return unless File.exist?(path)

  content = File.binread(path)
  base64 = Base64.strict_encode64(content)

  "data:#{content_type};base64,#{Rack::Utils.escape(base64)}"
end