Skip to content

Cannot control root option at serializer level anymore in 0.10.0rc5 #1683

Closed
@bolthar

Description

In 0.8, it was possible to determine if the serializer should include a root element or not via the root option, like so:

class MySerializer < ActiveModel::Serializer
  self.root = (((true or false)))
end

This has been removed in 0.10, and setting self.config.adapter = :attributes instead does nothing. Actually, it seems that the settings at the class level are ignored altogether.

By taking a look at https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializer/configuration.rb , one would expect that it should be possible to change the settings at the class level (there's even a comment that mentions it), but it doesn't seem to be possible. The options hash on classes deriving from ActiveModel::Serializeris always empty ({}), while I would have expected to see the default values in it. If I do something like:

class MyTestClass 
  include ActiveModel::Serializer::Configuration
end

then MyTestClass.confighas the expected values in it.

I can change the settings in an initializer, but that's global.

Would it be possible to change the root behavior at the class level again?

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions