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 asset_pipeline_loader #145
Comments
It seems the OP at rails/sprockets-rails#237 also posted about it at: reactjs/react-rails#241 I haven't been able to look into this yet as I need to revert back but wanted to mention the issue while I noticed it and had all this info. |
Thanks for reporting. Does this error pop up only in production or also in development? I'm currently not using this gem and thus haven't come across this. I guess the fix would be to augment the check in |
I am experiencing this issue in production and wasn't able to reproduce it in development. I haven't had time to write a pull request with proper tests and to maintain compatibility with sprockets 2, I do have a branch as a work around that is working for us in production if anyone else needs an immediate fix or needs a starting point to a more proper fix. https://github.com/stevestmartin/premailer-rails/tree/sprockets3 |
|
Thanks for the quick fix. Just came here with the same issue (production only), saw it was fixed, updated the gem to 1.9.0 (was 1.8.2) and it seems to be ok. |
Still broken! This fix makes it so the assets can no longer be found in production. Looking at rails/sprockets-rails#311, it seem this gem should use A workaround for now (in the email template), works correctly in production and development: link[rel='stylesheet' type='text/css'
href="/assets/#{Rails.application.config.assets.compile ? 'email.css' : assets_manifest.assets['email.css']}"]
|
@glebm |
@fphilipe It should use |
Maybe this helps? def asset_exist?(path)
if Rails.configuration.assets.compile
Rails.application.precompiled_assets.include? path
else
Rails.application.assets_manifest.assets[path].present?
end
end |
@DannyBen That may incorrectly report true if an asset has been precompiled, but then removed. I think premailer-rails should not attempt to use precompiled assets if |
Seeing as this is still an issue, can this be re-opened? |
where it was trying to call "find_asset" on Rails.application.assets when it was nil. Related: fphilipe/premailer-rails#145 This may resolve the issue in Aperta (in production environment) where inlining the CSS was failing. APERTA-6543
I've looked further into this issue. I don't understand why anyone would want to use the asset pipeline in production. Why don't you simply use |
@fphilipe yes I believe what you're missing is that this happens with <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width"/>
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet" type="text/css" />
<%= stylesheet_link_tag 'email' %>
<style type="text/css" data-premailer="ignore">
@media only screen and (max-width: 596px) {
... |
@javierjulio I don't follow. As far as I can tell, in development it will pick up the asset from the asset pipeline. In production the asset pipeline won't be available (this will be Are you using the asset pipeline in production? |
@fphilipe In production, even when using a CDN, the local file is often available (e.g. if using a caching proxy such as CloudFront), so it should pull the local file instead of making a network request to CloudFront. So the following order:
|
But @glebm Are you saying that it should use the asset pipeline strategy in production? I think it's not considered good practice to have that enabled as it is rather slow. Maybe I'm misunderstanding what you mean in point 2. Can you elaborate? |
@fphilipe I have to be honest, I'm not entirely sure how it all works under the hood. I went with this approach as its what I expect with Rails as if I were in a normal browser requested view. I did forget to point out that I do specify my email stylesheet in the config/initializers/assets.rb: # ...
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
Rails.application.config.assets.precompile += %w(
email.css
) |
@fphilipe For some reason that wasn't working when I last tried it, but will check again. |
I use sprockets-rails version > 3.0.0 and this line (requires gem compass-rails): CompassRails.sprockets.find_asset(logical_file_path).to_s instead of: Rails.application.assets.find_asset(logical_file_path).to_s and it works for me! If you don't use gem compass-rails you can get the asset with: (Rails.application.assets || ::Sprockets::Railtie.build_environment(Rails.application)).find_asset(logical_file_path).to_s |
Is this the proper way to get that logo? |
@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:
|
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 rails/sprockets-rails#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.
The text was updated successfully, but these errors were encountered: