# ActiveResource and collections

**URL:** <https://www.ruby-forum.com/t/activeresource-and-collections/70395>\
**Category:** Rails\
**Created:** [September 28, 2006, 9:01pm UTC](https://www.ruby-forum.com/t/activeresource-and-collections/70395 "2006-09-28T21:01:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bosko\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b77776/32.png) [@Bosko\_M](https://www.ruby-forum.com/u/Bosko_M)\
**Post date:** [September 28, 2006, 9:01pm UTC](https://www.ruby-forum.com/t/activeresource-and-collections/70395/1 "2006-09-28T21:01:23Z")

</div>

About RESTful collections, what do people think about “the correct”  
way of returning empty collections with Rails+ActiveResource?

Suppose I hit up a URI for a collection and the collection is empty.  
Should we return 404 or an empty container? I’m currently returning  
404 and this causes the ActiveResource client application to raise  
ActiveResource::ResourceNotFound even on a find(:all), which is  
different than how ActiveRecord behaves in the analogous scenario.

–  
Bosko M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.crowdedweb.com/](http://www.crowdedweb.com/)

---

<div class="post-metadata">

**Author:** ![Bosko\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b77776/32.png) [@Bosko\_M](https://www.ruby-forum.com/u/Bosko_M)\
**Post date:** [September 28, 2006, 9:35pm UTC](https://www.ruby-forum.com/t/activeresource-and-collections/70395/2 "2006-09-28T21:35:32Z")

</div>

(Appologies if this turns out to be a double-post… my first attempt  
does not appear to have gone through).

About RESTful collections, what do people think about “the correct”  
way of returning empty collections with Rails+ActiveResource?

Suppose I hit up a URI for a collection and the collection is empty.  
Should we return 404 or an empty container? I’m currently returning  
404 and this causes the ActiveResource client application to raise  
ActiveResource::ResourceNotFound even on a find(:all), which is  
different than how ActiveRecord behaves in the analogous scenario.

–  
Bosko M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.crowdedweb.com/](http://www.crowdedweb.com/)

---

<div class="post-metadata">

**Author:** ![Bosko\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b77776/32.png) [@Bosko\_M](https://www.ruby-forum.com/u/Bosko_M)\
**Post date:** [September 28, 2006, 9:45pm UTC](https://www.ruby-forum.com/t/activeresource-and-collections/70395/3 "2006-09-28T21:45:36Z")

</div>

On Sep 28, 2006, at 3:30 PM, Bosko M. wrote:

> different than how ActiveRecord behaves in the analogous scenario.  
> I think I’d lean towards returning an empty list. As I see it, a 404  
> should be issued if you don’t recognise the concept of that resource,  
> or if someone requests a specific resource that we don’t have, but if  
> the collection exists and is empty, we should say so.

In other words, if you have the resource types books and authors but  
not illustrators and the authors collection is empty I’d expect:

GET /books – a list of books  
GET /authors – an empty list  
GET /authors/1 – 404  
GET /illustrators – 404

James.

–  
James S. : Freelance Web D.  
Work : [http://jystewart.net](http://jystewart.net)  
Play : [http://james.anthropiccollective.org](http://james.anthropiccollective.org)

---

<div class="post-metadata">

**Author:** ![Bosko\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b77776/32.png) [@Bosko\_M](https://www.ruby-forum.com/u/Bosko_M)\
**Post date:** [September 28, 2006, 11:03pm UTC](https://www.ruby-forum.com/t/activeresource-and-collections/70395/4 "2006-09-28T23:03:57Z")

</div>

On 9/28/06, James S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 404 and this causes the ActiveResource client application to raise
> 
> GET /books – a list of books  
> GET /authors – an empty list  
> GET /authors/1 – 404  
> GET /illustrators – 404
> 
> James.

I agree with this rationale.

I submitted ticket#6291 [1] a couple of days ago which fixed ARes in  
the single-element-in-collection edge case, and I just uploaded a new  
diff which also fixes ARes find\_every when the collection is empty.

[1] [http://dev.rubyonrails.org/ticket/6291](http://dev.rubyonrails.org/ticket/6291)

–  
Bosko M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.crowdedweb.com/](http://www.crowdedweb.com/)
