-
Notifications
You must be signed in to change notification settings - Fork 326
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
parse_root_in_json true, but not in active_model_serializers_format or json_api_format problems #380
Comments
Hi Stephen, Thanks for writing in with your issue. I think the best course of action to The naming is probably a bit misleading since it indicates that one should Let me know if this fixes your issue. Thanks! On Wed, Oct 21, 2015 at 8:55 AM, Stephen Margheim [email protected]
|
@hubert That does fix my problem, but I'm not certain it's the best general fix. What is the point of If this seems acceptable, I can put in a PR. |
I ran into this same problem and I struggled with it for a while. I was eventually able to get it working by explicitly specifying: |
I may just put in a PR with this suggested fix. |
When moving a project from
ActiveResource
toher
, my team and I came across a problem. The API we are using (which is being built by our team for an enterprise application) wraps the JSON response in a model name (e.g.GET /api/v1/accounts
->{"accounts":[<data>]}
, orGET /api/v1/accounts/2
->{"account":{<data>}}
). This API, however, is not usingActiveModelSerializer
to generate the responses (it uses JBuilder templates, FWIW). When creating the models to be backed byher
, we simply had:Attempting to access that model threw an error, however:
Undefined method '.keys' for #<Array>
. In debugging this issue, I found that the problem lied in theextract_array
method in theparse.rb
file:The issue is that our
request_data
wasn't passing the firstif
clause, since I didn't state that the format was one of those two options, although the response was aHash
. This method thus simply returned the hash response (i.e.accounts: {<data>}
), instead of accessing the nested data.There are obviously numerous simple fixes (remove the second half of the
if
check, move that second half into a new nestedif
check, if Hash, try to accessrequest_data[:data][pluralized_parsed_root_element]
and handle possible errors, etc), but I don't presume to understand precisely what your large scale project decisions are that led to this particular implementation, thus I haven't yet put in a Pull Request.Hopefully, this is clear enough to display the issue that my team and I had. If not, let me know what else would prove valuable to you.
Love the project!
stephen
The text was updated successfully, but these errors were encountered: