Question

Here's what's happend: I have gone and pulled a large amount of data from an API. This is nice, but it includes a lot of results.

When I do a result.find(id: api_id) I get all the results like find was never performed. #where does not work either. I'm assuming this is because its not extending from Active Model.

Key Question: How do I find, say, the name of a particular object in an active resource collection?

Was it helpful?

Solution

Object.find(id: api_id) in active resource is essentially doing an api request as in (uri_of_api)/objects/:api_id)

But the :find method on an array is a different aninmal. You can look up the array 'find' method here... http://www.ruby-doc.org/core-2.1.1/Enumerable.html#method-i-find

The correct format would be...

result.find{|rec| rec.id == api_id}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top