From d40da11bf745dbf42029daf50c1ccbfd8176f254 Mon Sep 17 00:00:00 2001 From: Marwin Hochfelsner <50826859+hlfan@users.noreply.github.com> Date: Thu, 5 Mar 2026 07:34:03 +0000 Subject: [PATCH] Simplify AssetHelper logic paths --- app/helpers/asset_helper.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/helpers/asset_helper.rb b/app/helpers/asset_helper.rb index 238c61fc0..69a3482b6 100644 --- a/app/helpers/asset_helper.rb +++ b/app/helpers/asset_helper.rb @@ -2,20 +2,16 @@ module AssetHelper def assets(directory) - if (manifest = Rails.application.assets_manifest.assets) && !manifest.empty? - # With precompiled assets - manifest.keys.each_with_object({}) do |asset, assets| - assets[asset] = asset_path(asset) if asset.start_with?("#{directory}/") + asset_list = Rails.application.assets_manifest.assets.keys + if asset_list.empty? + # when assets are not precompiled + env = Rails.application.assets + env.each_file do |path| + asset_list << env[path]&.logical_path if path.include?(directory) end - elsif (env = Rails.application.assets) && env.present? - # Without precompiled assets - env.paths - .filter { |path| path.include?(directory) } - .flat_map { |path| Dir.glob(File.join(path, "**", "*")) } - .filter_map { |path| env.find_asset(path) } - .each_with_object({}) do |asset, assets| - assets[asset.logical_path] = asset_path(asset.logical_path) if asset.logical_path.start_with?("#{directory}/") - end + end + asset_list.each_with_object({}) do |asset, assets| + assets[asset] = asset_path(asset) if asset&.start_with?("#{directory}/") end end end -- 2.39.5