-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Starting Docs structure #994
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
minor updates and TYPOs
- Loading branch information
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# How to use add root key | ||
# How to add root key | ||
|
||
Add the root key to your API is quite simple with AMS. The **Adapter** is what determines the format of your JSON response. The default adapter is the ```FlattenJSON``` which doesn't have the root key, so your response is something similar to: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Adding a root key" |
||
|
||
|
@@ -10,19 +10,14 @@ Add the root key to your API is quite simple with AMS. The **Adapter** is what d | |
} | ||
``` | ||
|
||
In order to add the correspondent root key you need to use the ```JSON``` Adapter, you can change this in an initializer: | ||
In order to add the root key you need to use the ```JSON``` Adapter, you can change this in an initializer: | ||
|
||
```ruby | ||
ActiveModel::Serializer.config.adapter = :json_api | ||
ActiveModel::Serializer.config.adapter = :json | ||
``` | ||
|
||
or | ||
|
||
```ruby | ||
ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::Json | ||
``` | ||
|
||
This will add the root key to all your serialized endpoints. | ||
You can also specify a class as adapter, as long as it complies with the AMS adapters interface. | ||
It will add the root key to all your serialized endpoints. | ||
|
||
ex: | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that it can't be set from the controller or render command, but it can be overridden in the serializer or by subclassing the json adapter see #986 (comment) though I'm not sure to what extent we want to highlight here, or link to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I want to highlight this work-around now. I'm also still considering bring
root
option back so we might to update it soon.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh... why can't it be overridden? 😢 I think it should be...