-
Notifications
You must be signed in to change notification settings - Fork 81
Closed
Labels
Description
This makes no sense to me... By the time you want to invoke jsonapi_render the request object has been processed and you're formulating the response.
I assume you're doing it to set some context/variables that you share among your util methods, but is there another reason?
This is an example of why this puzzles and frustrates me.
At debugger in controller:
8: if creator.save
=> 9: binding.pry
10: jsonapi_render json: creator.session, status: :createdjsonapi_serialize is fine:
[1] pry(#<Api::V1::SessionsController>)> jsonapi_serialize creator.session
{:data=>{"id"=>"9a5ad4ef-4e97-40a8-a884-daffd1c43db1", "type"=>"sessions", "links"=>{:self=>"http://example.org/api/v1/sessions/9a5ad4ef-4e97-40a8-a884-daffd1c43db1"}, "relationships"=>{"credential"=>{:links=>{:self=>"http://example.org/api/v1/sessions/9a5ad4ef-4e97-40a8-a884-daffd1c43db1/relationships/credential", :related=>"http://example.org/api/v1/sessions/9a5ad4ef-4e97-40a8-a884-daffd1c43db1/credential"}}}}}jsonapi_render is not:
[3] pry(#<Api::V1::SessionsController>)> jsonapi_render json: creator.session, status: :created
"{\"errors\":[{\"title\":\"Param not allowed\",\"detail\":\"email is not allowed.\",\"id\":null,\"href\":null,\"code\":\"105\",\"source\":null,\"links\":null,\"status\":\"400\",\"meta\":null},{\"title\":\"Param not allowed\",\"detail\":\"password is not allowed.\",\"id\":null,\"href\":null,\"code\":\"105\",\"source\":null,\"links\":null,\"status\":\"400\",\"meta\":null}]}"Sorry for venting a bit here. I just don't understand why we need to have such an explicit tie between the request and the response. Depending on the application they may not share parameters, like in our case.
halilim