Skip to content

ActiveResource find() not following JSON api #75

Open
hoetmaaiers opened this Issue May 22, 2013 · 3 comments

4 participants

@hoetmaaiers

When following the JSON API document, I return my singular resources in an array as described:

 {
   "designs": [
    {
      // individual design
    }
  ]
}

My app talking to the API uses ActiveResource. When I do a find in ActiveRescource

Api::Design.find(10)

I get the following error:

ArgumentError: expected an attributes Hash, got [{"id"=>10, "title"=>" ...

ActiveResource seems to have trouble with return singular resources as an array.
Any thoughts or help on this?

@radar
radar commented May 27, 2013

Active Resource expects an attributes hash back. If you're working with an API that doesn't conform to Active Resource exactly, I would strongly recommend looking into using something different, such as HTTParty, to provide the code that talks with your API.

@Fivell
Fivell commented Aug 27, 2013

or you can use custom formatter

@cmarkle
cmarkle commented Dec 28, 2013

See the comments in the collections class https://github.com/rails/activeresource/blob/master/lib/active_resource/collection.rb about using a collections parser. This worked for me in exactly the situation you described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.