Open seanabrahams opened 6 years ago
Making this helper method safe seems like a good idea for me and I will sure work on a refactoring asap.
Anyway, I'm curious on how you came to reach that error. Since :data
is not present for the given operation and it probably requires the JSON body to be present (eg. POST
, PUT
, PATCH
request), if an empty/bad formatted body is passed it should be verified and treated before calling the controller action.
It was via a request like GET /profile/:profile_id/articles
where it was looking for a profile_id
in params[:profile_id]
OR resource_params[:profile_id]
.
The question then is, why look in resource_params[:profile_id]
if it's a GET
request? The answer is that I'm trying to keep the code DRY and avoid a conditional like if request.get?
.
Ultimately, calling resource_params
, even on a GET
request, should not throw an exception (in my opinion).
I have a nested resource where the
index
action has a code path that executesresource_params
which ends up producing:Due to:
https://github.com/tiagopog/jsonapi-utils/blob/v0.4.9/lib/jsonapi/utils/request.rb#L77
@request.operations
contains:Which does not include a
:data
key, hence the resulting exception.One option is to update the offending piece of code to:
I'll look into submitting a PR. In the meantime I've rescued the exception.