You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'source' is missing when model errors are serialized #69
{
"errors":
[
{
"title": "Invalid occurred_at",
"detail": "Occurred at Future time is not allowed",
"source":
{
}
},
{
"title": "Invalid code",
"detail": "Code This status is in conflict with the previous one",
"source":
{
}
}
],
"jsonapi":
{
"version": "1.0"
}
}
It has two issues: 1) 'source' value is missing, 2) The detail of the message shouldn't contain the source attribute. For example instead of 'Occurred at Future time is not allowed' it should be 'Future time is not allowed'.
Regarding source, it will only work out of the box if you're using deserializable_resource to deserialize the input payload. There's room for improvement there, but that's the current status.
Regarding the detail, I agree, and I'd merge a PR fixing this behavior (it happens here).
I'm trying to use it with deserializable_resource but the source is not been populated out of the box. I had to add the method jsonapi_pointers.
For example:
class UserController < ApplicationController
deserializable_resource :user, only: [:create, :update]
def create
user = User.new(user_params)
if user.save
render jsonapi: user
else
render jsonapi_errors: user.errors, status: :unprocessable_entity
end
end
def jsonapi_pointers
{
name: '/data/attributes/name',
email: '/data/attributes/email'
}
end
private
def user_params
params.require(:user).permit(:name, :email)
end
end
@aamir-pk by the way, here's how to use the deserializable_resource in a controller
Activity
beauby commentedon Nov 16, 2017
Thanks for bringing this up.
Regarding
source, it will only work out of the box if you're usingdeserializable_resourceto deserialize the input payload. There's room for improvement there, but that's the current status.Regarding the
detail, I agree, and I'd merge a PR fixing this behavior (it happens here).aamir-pk commentedon Nov 17, 2017
Thanks for your response. I will be thankful if you can show me how to add
deserializable_resourceinrendercommand.Thanks
filipecrosk commentedon Jan 22, 2018
I'm trying to use it with
deserializable_resourcebut the source is not been populated out of the box. I had to add the methodjsonapi_pointers.For example:
@aamir-pk by the way, here's how to use the
deserializable_resourcein a controllerJoeWoodward commentedon Jan 30, 2018
You don't need to use
jsonapi_pointers. Are you using the correct mime type and have it registered?FYI
deserializable_resource :symbolwill make the deserialized params available asparams[:symbol]I added a comment to this issue which may help #79
filipecrosk commentedon Jan 30, 2018
Thanks @JoeWoodward but unfortunately it didn't fix for me.
I tried to register the mime type as you mentioned on the #79 issue but I don't think it was the case for me. Also, it looks like it is already registered here https://github.com/jsonapi-rb/jsonapi-rails/blob/master/lib/jsonapi/rails/railtie.rb#L35
I'm using Ember data and my frontend is always sending the correct content type:
Content-Type:application/vnd.api+jsonJoeWoodward commentedon Jan 31, 2018
I had not noticed the railtie specified the mime type. Thanks for pointing that out
patodevilla commentedon Mar 31, 2018
I am also having some trouble with this, some attributes return source and some don't. I am using the deserializable_resource method.