From 4adf712c26b4f7cf01d71ab238a810b718e08a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 16 Apr 2019 17:05:04 +0200 Subject: [PATCH] Prepend custom assets to CONSUL assets Rails 5 changed the initialization order, and now our initializers were running before the `append_assets_path` initializer for each engine, which prepended application assets to the custom assets we prepended in the initializer. Moving the code to the `config.after_initialize` code didn't work either, since the paths added there were ignored by the application. Adding another initializer to the Rails Engine is a hack, but solves the problem. --- config/application.rb | 10 ++++++++++ config/initializers/assets.rb | 5 ----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/config/application.rb b/config/application.rb index f4345061a..6ef88f5ea 100644 --- a/config/application.rb +++ b/config/application.rb @@ -71,4 +71,14 @@ module Consul end end +class Rails::Engine + initializer :prepend_custom_assets_path, group: :all do |app| + if self.class.name == "Consul::Application" + %w[images fonts javascripts].each do |asset| + app.config.assets.paths.unshift(Rails.root.join("app", "assets", asset, "custom").to_s) + end + end + end +end + require "./config/application_custom.rb" diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index cbd07efbf..4990ba4d0 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -16,8 +16,3 @@ Rails.application.config.assets.precompile += %w( print.css ) Rails.application.config.assets.precompile += %w( ie.css ) # Loads custom images and custom fonts before app/assets/images and app/assets/fonts -assets_path = Rails.application.config.assets.paths - -%w[images fonts javascripts].each do |asset| - assets_path.insert(0, Rails.root.join("app", "assets", asset, "custom").to_s) -end