There is an issue when root element is configured this way :
ActiveSupport.on_load(:active_model_serializers) do
# Disable for all serializers (except ArraySerializer)
ActiveModel::Serializer.root = false
# Disable for ArraySerializer
ActiveModel::ArraySerializer.root = false
end
Actually the gem is doing that :
def self.version(version, superclass = ActiveModel::Serializer, &block)
base_class = self
vklass = Class.new(superclass) do
self.root(base_class._root)
alias_method base_class._name.to_sym, :object
singleton_class.class_eval do
define_method(:to_s) do
"(#{base_class.name} VERSION: #{version})"
end
alias inspect to_s
end
It sets root (or not) directly based on parameters passed to the serializer :
There is an issue when root element is configured this way :
Actually the gem is doing that :
It sets root (or not) directly based on parameters passed to the serializer :
You can notice that it doesn't use my configuration and still includes the root element because it doesn't check if
superclass._root?
isfalse
.