Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ActiveResource find() not following JSON api #75

Open
hoetmaaiers opened this Issue · 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

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

or you can use custom formatter

@cmarkle

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.