Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use Rails.application.assets #105

Open
sepastian opened this issue Mar 17, 2016 · 3 comments
Open

Don't use Rails.application.assets #105

sepastian opened this issue Mar 17, 2016 · 3 comments

Comments

@sepastian
Copy link

I have updated sprockets and now get ActionView::Template::Error (undefined methodfind_asset' for nil:NilClass)`.

Rails.application.assets is nil unless assets.compile is set, which defaults to false in production.

See rails/sprockets-rails#237, i.e.:

So it sounds like using those gems may have been behaving poorly in production before.

sepastian added a commit to sepastian/spree_print_invoice that referenced this issue Mar 17, 2016
@mdavo6
Copy link
Contributor

mdavo6 commented Nov 14, 2016

I had the same issue. Was able to resolve by changing the first few lines of _header.pdf.prawn to:

rel_path = Rails.application.assets_manifest.assets[Spree::PrintInvoice::Config[:logo_path]]
im = Rails.root.join("public","assets",rel_path)

if im && File.exist?(im)
  pdf.image im, vposition: :top, height: 40, scale: Spree::PrintInvoice::Config[:logo_scale]
end

@aman29april
Copy link

@mdavo6 This solution doesn't work in the development environment.

@mdavo6
Copy link
Contributor

mdavo6 commented Nov 15, 2018

@aman29april Agree. Have just had some time to work on a better solution which works in production and development. What about the below as an approach? Working for me in development and production.

if Rails.env.production? && 
Rails.application.assets_manifest.assets[Spree::PrintInvoice::Config[:logo_path]].present?
  manifest_dir = Rails.application.assets_manifest.dir
  logo_path = Rails.application.assets_manifest.assets[Spree::PrintInvoice::Config[:logo_path]]
  im = File.join(manifest_dir, logo_path)
elsif Rails.application.assets.find_asset(Spree::PrintInvoice::Config[:logo_path]) != nil
  im = Rails.application.assets.find_asset(Spree::PrintInvoice::Config[:logo_path]).filename
end

if im && File.exist?(im)
  pdf.image im, vposition: :top, height: 40, scale: Spree::PrintInvoice::Config[:logo_scale]
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants