From cf18544e3ab8fedc0063fb39257f7b66a2b61167 Mon Sep 17 00:00:00 2001 From: Nicolas Blanco Date: Fri, 9 Jun 2017 02:05:26 +0200 Subject: [PATCH] Conditionally load LocaleController only if frontend is loaded --- {app => lib}/controllers/spree/locale_controller.rb | 0 lib/spree_i18n/engine.rb | 10 ++++++++++ 2 files changed, 10 insertions(+) rename {app => lib}/controllers/spree/locale_controller.rb (100%) diff --git a/app/controllers/spree/locale_controller.rb b/lib/controllers/spree/locale_controller.rb similarity index 100% rename from app/controllers/spree/locale_controller.rb rename to lib/controllers/spree/locale_controller.rb diff --git a/lib/spree_i18n/engine.rb b/lib/spree_i18n/engine.rb index 964f37f68..8673e140d 100644 --- a/lib/spree_i18n/engine.rb +++ b/lib/spree_i18n/engine.rb @@ -26,6 +26,16 @@ def self.activate Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c| Rails.configuration.cache_classes ? require(c) : load(c) end + + if self.frontend_available? + Dir.glob(File.join(File.dirname(__FILE__), '../controllers/**/*.rb')) do |c| + Rails.configuration.cache_classes ? require(c) : load(c) + end + end + end + + def self.frontend_available? + @@frontend_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Frontend::Engine') end config.to_prepare(&method(:activate).to_proc)