Skip to content

Commit 4c0da9e

Browse files
committed
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.
1 parent a081a06 commit 4c0da9e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/inline_svg/railtie.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@ class Railtie < ::Rails::Railtie
1010

1111
config.after_initialize do |app|
1212
InlineSvg.configure do |config|
13-
# In default Rails apps, this will be a fully operational
14-
# Sprockets::Environment instance
13+
# Configure the asset_finder:
1514
# Only set this when a user-configured asset finder has not been
1615
# configured already.
1716
if config.asset_finder.nil?
1817
if assets = app.instance_variable_get(:@assets)
18+
# In default Rails apps, this will be a fully operational
19+
# Sprockets::Environment instance
1920
config.asset_finder = assets
2021
elsif defined?(Webpacker)
22+
# Use Webpacker when it's available
2123
config.asset_finder = InlineSvg::WebpackAssetFinder
24+
else
25+
# Fallback to the StaticAssetFinder if all else fails.
26+
# This will be used in cases where assets are precompiled and other
27+
# production settings.
28+
config.asset_finder = InlineSvg::StaticAssetFinder
2229
end
2330
end
2431
end

0 commit comments

Comments
 (0)