Skip to content

Commit 6713864

Browse files
committed
combine config initializers and update comments
this also changes the action_controller load hook to not trigger loading of the ActionController::Base
1 parent d3bdc9b commit 6713864

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

lib/active_model_serializers/railtie.rb

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,15 @@ class Railtie < Rails::Railtie
1111

1212
initializer 'active_model_serializers.action_controller' do
1313
ActiveSupport.on_load(:action_controller) do
14-
ActionController::Base.send(:include, ::ActionController::Serialization)
14+
include(::ActionController::Serialization)
1515
end
1616
end
1717

18-
initializer 'active_model_serializers.logger', :after => 'action_controller.set_configs' do
18+
# This hook is run after the action_controller railtie has set the configuration
19+
# based on the *environment* configuration and before any config/initializers are run
20+
# and also before eager_loading (if enabled).
21+
initializer 'active_model_serializers.set_configs', :after => 'action_controller.set_configs' do
1922
ActiveModelSerializers.logger = Rails.configuration.action_controller.logger
20-
end
21-
22-
# To be useful, this hook must run after Rails has initialized,
23-
# BUT before any serializers are loaded.
24-
# Otherwise, the call to 'cache' won't find `cache_store` or `perform_caching`
25-
# defined, and serializer's `_cache_store` will be nil.
26-
# IF the load order cannot be changed, then in each serializer that that defines a `cache`,
27-
# manually specify e.g. `PostSerializer._cache_store = Rails.cache` any time
28-
# before the serializer is used. (Even though `ActiveModel::Serializer._cache_store` is
29-
# inheritable, we don't want to set it on `ActiveModel::Serializer` directly unless
30-
# we want *every* serializer to be considered cacheable, regardless of specifying
31-
# `cache # some options` in a serializer or not.
32-
initializer 'active_model_serializers.caching', :after => 'action_controller.set_configs' do
3323
ActiveModelSerializers.config.cache_store = Rails.configuration.action_controller.cache_store
3424
ActiveModelSerializers.config.perform_caching = Rails.configuration.action_controller.perform_caching
3525
end

0 commit comments

Comments
 (0)