From 4c0da9ecc56e34cc2ae42ee05cd91a05f99d3405 Mon Sep 17 00:00:00 2001 From: James Martin Date: Tue, 18 Jun 2019 17:32:07 +1000 Subject: [PATCH] Fallback to StaticAssetFinder In production environments where assets are precompiled it's possible for the @assets instance variable to be nil and also Webpacker to not be used. Falling back to the StaticAssetFinder covers this case. --- lib/inline_svg/railtie.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/inline_svg/railtie.rb b/lib/inline_svg/railtie.rb index dec905b..c066819 100644 --- a/lib/inline_svg/railtie.rb +++ b/lib/inline_svg/railtie.rb @@ -10,15 +10,22 @@ class Railtie < ::Rails::Railtie config.after_initialize do |app| InlineSvg.configure do |config| - # In default Rails apps, this will be a fully operational - # Sprockets::Environment instance + # Configure the asset_finder: # Only set this when a user-configured asset finder has not been # configured already. if config.asset_finder.nil? if assets = app.instance_variable_get(:@assets) + # In default Rails apps, this will be a fully operational + # Sprockets::Environment instance config.asset_finder = assets elsif defined?(Webpacker) + # Use Webpacker when it's available config.asset_finder = InlineSvg::WebpackAssetFinder + else + # Fallback to the StaticAssetFinder if all else fails. + # This will be used in cases where assets are precompiled and other + # production settings. + config.asset_finder = InlineSvg::StaticAssetFinder end end end