Skip to content

Commit

Permalink
Fallback to StaticAssetFinder
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jamesmartin committed Jun 18, 2019
1 parent a081a06 commit 4c0da9e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/inline_svg/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c0da9e

Please sign in to comment.