Use plural of resource type for controller#988
Open
hidde-jan wants to merge 2 commits intoJSONAPI-Resources:masterfrom
Open
Use plural of resource type for controller#988hidde-jan wants to merge 2 commits intoJSONAPI-Resources:masterfrom
hidde-jan wants to merge 2 commits intoJSONAPI-Resources:masterfrom
Conversation
Currently, doing `jsonapi_resource :current_user` will use the `CurrentUserController`, however, any relationships on the `current_user` resource will instead look for the `CurrentUsersController`. By default, rails uses the plural name controller for any singular resource. Keeping this the same for JA:R seems like a good idea.
Contributor
Author
|
Actually, relationships for singular resources also seem broken (at least in 0.8.3). If I {
"errors": [
{
"code": "PARAM_MISSING",
"detail": "The required parameter, current_user_id, is missing.",
"status": "400",
"title": "Missing Parameter"
}
]
}Edit: I did some more checking. The only way this can currently be worked around is to trick the RequestParser into thinking a valid key was passed, i.e. by overriding class CurrentUserResource < JSONAPI::Resource
def self._as_parent_key
:source
end
def self.verify_key(key, context = {})
if key == "current_users" && context[:current_user]
context[:current_user].id
else
super
end
end
endEdit 2: |
|
I'm running against this issue as well. Thanks for the details :) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, doing
jsonapi_resource :current_userwill use theCurrentUserController, however, any relationships on thecurrent_userresource will instead look for theCurrentUsersController. By default, rails uses the plural name controller for any singular resource. Keeping this the same for JA:R seems like a good idea.This is currently not picked up by the tests currently, since
Preferencesis already a plural.