Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/action_controller/serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def serialization_scope(scope)
end
end

class << self
attr_accessor :enabled
end
self.enabled = true
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(pardon the awful pseudo code)

I was actually just thinking about having

  • a configurable default 'ams_ify_controller = true`
  • and then in the controller, by default we only mix in a 'shim' module that
    • has config methods, e.g. ams_ify_controller
    • so that by default ActionController::Serialization would be included in action controller
    • but if the default were set to false, then individual controllers would need to opt in by setting ams_ify_controller true .
    • the method would just extend the controller with ActionController::Serialization when true


included do
class_attribute :_serialization_scope
self._serialization_scope = :current_user
Expand Down
11 changes: 5 additions & 6 deletions lib/active_model_serializers/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ class Railtie < Rails::Railtie
ActiveModel::Serializer.serializers_cache.clear
end

initializer 'active_model_serializers.action_controller' do
ActiveSupport.on_load(:action_controller) do
include(::ActionController::Serialization)
end
end

initializer 'active_model_serializers.prepare_serialization_context' do
SerializationContext.url_helpers = Rails.application.routes.url_helpers
SerializationContext.default_url_options = Rails.application.routes.default_url_options
Expand All @@ -29,6 +23,11 @@ class Railtie < Rails::Railtie
# We want this hook to run after the config has been set, even if ActionController has already loaded.
ActiveSupport.on_load(:action_controller) do
ActiveModelSerializers.config.cache_store = cache_store
# Only include controller mixin when enabled
# https://github.com/rails-api/active_model_serializers/issues/1500
# https://github.com/rails-api/active_model_serializers/pull/592
# Rails.configuration.action_controller.render_json_with_active_model_serializers
include ::ActionController::Serialization if ::ActionController::Serialization.enabled
end
end

Expand Down