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

undefined method `find_asset' for nil:NilClass in production with sprockets-rails 3.0.0 #476

Closed
Bonias opened this issue Dec 21, 2015 · 8 comments

Comments

@Bonias
Copy link

Bonias commented Dec 21, 2015

wicked_pdf_stylesheet_link_tag fails with NoMethodError: undefined method 'find_asset' for nil:NilClass in production with sprockets-rails 3.0.0

See here: rails/sprockets-rails#237


Something like this probably can be used instead of Rails.application.assets.find_asset:

manifest = Rails.application.assets_manifest
path = File.join(manifest.dir, manifest.assets['file.css'])
File.read(path)
@leesmith
Copy link

I'm seeing the same thing with rails 4.2.5 and sprockets-rails 3.0.0.

@KeirSurvival
Copy link

And me. Same versions as leesmith.

@MaximilianoFelice
Copy link

I'm getting this same error on a Heroku instance. Any known versions where this doesn't happen?

@unixmonkey
Copy link
Collaborator

@MaximilianoFelice Looks like any version of sprockets-rails less than 3.0 should work for now, but your issue may not be related. There's a number of reasons your asset might not be found.

@Bonias Would you be able to help test out that bit of code on a few different versions of Rails and send a PR?

@MaximilianoFelice
Copy link

@unixmonkey It seems to be the same issue described on the link provided by @Bonias, as turning assets.compile = true "fixes" it.

According to that link, by the way, sprockets team isn't very much willing to match the old behaviour any soon.

@aliyazdani
Copy link

rails 4.2, seeing the same issue in prod.

@cesc1989
Copy link

cesc1989 commented Jan 6, 2016

+1

Rails 4.2.0
Sprockets-rails 3.0.0
Production environment

Did same thing as MaximilianoFelice

assets.compile = true and it got fixed.

Bonias pushed a commit to Bonias/wicked_pdf that referenced this issue Jan 7, 2016
Remove `asset_exists?` method. Replace it with `File.file?` at `read_asset`.
Fix issue handled by `asset_exists?` at `wicked_pdf_stylesheet_link_tag` by
changing `asset_pathname` method.
`asset_exists?` coused problems with sprockets 3.0 so removing it fixes that.

Always process assets at `wicked_pdf_stylesheet_link_tag` with
`wicked_pdf_asset_path`. This fixes issue when
`url(http://example.com/rails.png)` was removed.

Rename `precompiled_asset?` to `precompiled_or_absolute_asset?` - this more
precisely describe what this method does. Additionally return `true` if
argument string starts with "http://" or "http://".

Change `asset_pathname` to always return some value when assets compilation
is enabled. This fixes problem when exception is raised when asset doesn't
exists.

Change `read_asset` to check if file exists before read it.
unixmonkey added a commit that referenced this issue Jan 8, 2016
Fix #476 issue - problem with sprockets 3.0
@phlegx
Copy link

phlegx commented Jun 14, 2016

Please read my solution here: http://stackoverflow.com/a/37820647/132235

chrisma added a commit to hpi-swt2/wimi-portal that referenced this issue Jan 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants