-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array root documentation #81
Comments
I am currently toying with patching a custom module EndpointExtension
def render_collection(resources, serializer:, root:)
{root => ActiveModel::Serializer::CollectionSerializer.new(resources, serializer: serializer, scope: self)}
end
end
Grape::Endpoint.send(:include, EndpointExtension) |
@stevelacey - can you check what your adapter is set to? The default AMS adapter is See https://github.com/rails-api/active_model_serializers/blob/v0.10.6/docs/general/adapters.md for details. You can override the default by adding |
Yeah it’s set to json
…On Wed, 8 Nov 2017 at 16:20, Darren Cheng ***@***.***> wrote:
@stevelacey <https://github.com/stevelacey> - can you check what your
adapter is set to? The default AMS adapter is attributes, which ignores
that root option. Perhaps you want to use the json adapter.
See
https://github.com/rails-api/active_model_serializers/blob/v0.10.6/docs/general/adapters.md
for details.
You can override the default by adding ActiveModelSerializers.config.adapter
= :json in an initializer.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#81 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARq-33xRyKq2GSKhZ4y9J2vBDLUqjYOks5s0XJlgaJpZM4QI6hK>
.
|
Maybe I am missing the point... but I don't understand how, why or when the
root
option works – I am putting it in all sorts of places, onget/post
, onnamespaces/resources
, onCollectionSerializer
constructs... and it is never doing what I expect.I am expecting
root: 'users'
to make the output:I see past issues that this changed at some point, is there documentation missing around this?
Also I found an issue from years ago that seemed to indicate
root: false
stopped working on collections at some point – that'd be handy tooAm I right in thinking that a CollectionSerializer with a
root
option doesn't realise that root until anAdapter
handles it or something?In a bunch of cases in the API I am working on we are returning
CollectionSerializer
instances from controller action, I've been toying with switching those to arender
call – but that doesn't accept any options eitherThe text was updated successfully, but these errors were encountered: