premailer-rails: undefined method `find_asset' for nil:NilClass in asset_pipeline_loader
Today I updated the sprockets-rails gem which is now at 3.0.0 and noticed an error occurring after updating: “NoMethodError·undefined method `find_asset’ for nil:NilClass”. I’m using latest premailer-rails 1.8.2. The error is is happening here: https://github.com/fphilipe/premailer-rails/blob/master/lib/premailer/rails/css_loaders/asset_pipeline_loader.rb#L10
Noticed the issue reported on sprockets-rails https://github.com/rails/sprockets-rails/issues/237 back in April for the 3.0 version. I didn’t see what the fix was but it was mentioned that it was resolved in react-rails. I figure the same issue that happened there is probably happening here.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 21 (8 by maintainers)
Links to this issue
Commits related to this issue
- Update premailer-rails to include a fix where it was trying to call "find_asset" on Rails.application.assets when it was nil. Related: https://github.com/fphilipe/premailer-rails/issues/145 This may... — committed to Aperta-project/Aperta by zdennis 8 years ago
- Add workaround for broken upstream premailer-rails https://github.com/fphilipe/premailer-rails/issues/145 — committed to Aperta-project/Aperta by egh 8 years ago
I use sprockets-rails version > 3.0.0 and this line (requires gem compass-rails):
instead of:
and it works for me!
If you don’t use gem compass-rails you can get the asset with:
@phlegx’s last solution works out-of-the-box, using Rails 4.2.1.
I’ve packaged it in a helper method in my app:
Still broken! This fix makes it so the assets can no longer be found in production. Looking at https://github.com/rails/sprockets-rails/issues/311, it seem this gem should use
Rails.application.assets_manifest.assets[filename]to get the correct path to the compiled file in production.A workaround for now (in the email template), works correctly in production and development: