Mange / roadie-rails

Making HTML emails comfortable for the Rails rockstars
MIT License
363 stars 65 forks source link

AssetPipelineProvider fails in Rails 4.2? #36

Closed mcolyer closed 9 years ago

mcolyer commented 9 years ago

So it looks like the AssetPipelineProvider is passed an asset path with the digest in rails 4.2. However normalize_asset_name doesn't remove the digest from the filename.

Unfortunately sprockets can't locate that asset with the digest attached, which causes roadie to fail with

Roadie::CssNotFound

Could not find stylesheet "/assets/ink-f31b199e0707d07b7545a85a961e81eb.css?body=1"
Used provider:
ProviderList: [
  #<Roadie::FilesystemProvider:0x007f90d9e5bf70>,
  #<Roadie::Rails::AssetPipelineProvider:0x007f90d9e5acb0>
]

I'm not sure what the best way to fix this but I'm open to suggestions.

Mange commented 9 years ago

Why isn't the file on the filesystem? Have you precompiled your assets in whichever machine is doing the email generation?

sön 1 mar 2015 02:43 Matt Colyer notifications@github.com skrev:

So it looks like the AssetPipelineProvider is passed an asset path with the digest in rails 4.2. However normalize_asset_name https://github.com/Mange/roadie-rails/blob/92ebd8b8b3f76f294cce2eb5cfdde91713d9bcdd/lib/roadie/rails/asset_pipeline_provider.rb#L20-L22 doesn't remove the digest from the filename.

Unfortunately sprockets can't locate that asset https://github.com/Mange/roadie-rails/blob/92ebd8b8b3f76f294cce2eb5cfdde91713d9bcdd/lib/roadie/rails/asset_pipeline_provider.rb#L14 with the digest attached, which causes roadie to fail with

Roadie::CssNotFound

Could not find stylesheet "/assets/ink-f31b199e0707d07b7545a85a961e81eb.css?body=1" Used provider: ProviderList: [

Roadie::FilesystemProvider:0x007f90d9e5bf70,

Roadie::Rails::AssetPipelineProvider:0x007f90d9e5acb0

]

I'm not sure what the best way to fix this but I'm open to suggestions.

— Reply to this email directly or view it on GitHub https://github.com/Mange/roadie-rails/issues/36.

mcolyer commented 9 years ago

@Mange in rails 4.2, digests are now enabled in development however the cached files aren't actually written to disk.

So it sounds like it's change in default behavior.

Mange commented 9 years ago

Thanks for the link. It appears like Rails is trying to make asset handling harder for everyone again. :-/

I wish they provided an API to get assets from the actual path presented in the template, but we'll have to settle for stripping the digest off and regenerating the assets every time. Asking Rails for a specific asset will do a live compilation, which is very slow, even though a precompiled asset exist on disk. (Maybe this changed as well in newest Sprockets?)

Could you try the #34 PR fork and see if that solves your issue? I might need to fast track this into a patch release.

mcolyer commented 9 years ago

@Mange yep I've confirmed that PR fixes my issue.

Mange commented 9 years ago

I've released version 1.0.5 with the aforementioned PR inside it. Thank you for reporting! :+1:

dmarkow commented 9 years ago

On a fresh/default Rails 4.2.1 app, Sprockets is giving me hashes with 64 characters (e.g. "6d70c2d632517a56d6d00d83815ffcc07c0e44e4867235f85b0ca71a53b92dc5") instead of 32, so this fix isn't working. I haven't had a chance to look into why this might be happening yet, but it's blocking me from upgrading to Roadie 3.x.

dmarkow commented 9 years ago

https://github.com/rails/sprockets/blob/master/CHANGELOG.md

It looks like Sprockets was recently (April 12th) changed to default to Digest::SHA256 (which is 64 characters). Since Rails doesn't lock to 2.x of Sprockets, updating your gems will move Sprockets to 3.x which will trigger this error.