# What's the most RESTful approach here?

**URL:** <https://www.ruby-forum.com/t/whats-the-most-restful-approach-here/171882>\
**Category:** Rails\
**Created:** [July 10, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/whats-the-most-restful-approach-here/171882 "2009-07-10T18:55:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dr\_gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@dr\_gavin](https://www.ruby-forum.com/u/dr_gavin)\
**Post date:** [July 10, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/whats-the-most-restful-approach-here/171882/1 "2009-07-10T18:55:52Z")

</div>

Hi all

I’m working on an app at the moment and I’m trying to think of the  
most RESTful way of implementing one of the key parts of the site.

Some advice on the best approach would really help.

To give you an example, I have one model but it’s split into three  
different categories: lost, found, broken.

Users can browse them by category but never all together.

My initial reaction is simply to have one index and determine the  
category by parameter:

[www.mypage.com/items?category=lost](http://www.mypage.com/items?category=lost)

This seems like the DRYest option.

This would mean one of the categories should be the ‘default’ though,  
if no parameters were specified or if they were invalid.

But each category is just as relevant as the others so this option  
isn’t great.

After thinking about it, these are separate indexes so my next  
reaction was to have four controllers:

items ( new, create, edit, update and destroy)  
found\_items ( index )  
lost\_items ( index )  
broken\_items ( index )

This would give really clear routes and urls but it means creating  
four separate controllers - seems like overkill no?

The third option I’ve considered is to name three collections in my  
routes and add three actions to my items controller:

map.resources :items, :collection =\> { :lost =\> :get, :found  
=\> :get, :broken =\> :get }

def lost  
@items = Item.lost  
end

…and so on.

Again, quite clear routes and descriptive urls but I’m under the  
impression that this is a less RESTful approach.

Any thoughts?

Thanks

Gavin

---

<div class="post-metadata">

**Author:** ![dr\_gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@dr\_gavin](https://www.ruby-forum.com/u/dr_gavin)\
**Post date:** [July 10, 2009, 9:01pm UTC](https://www.ruby-forum.com/t/whats-the-most-restful-approach-here/171882/2 "2009-07-10T21:01:28Z")

</div>

On Jul 10, 2009, at 12:55 PM, Gavin wrote:

> Users can browse them by category but never all together.
> 
> @items = Item.lost
> 
> Gavin

I’d say go with the third one and define the actions on your resource.  
Then you can define your index action to offer a choice of the  
available categories (perhaps with a handy record count).

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dr\_gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@dr\_gavin](https://www.ruby-forum.com/u/dr_gavin)\
**Post date:** [July 10, 2009, 10:54pm UTC](https://www.ruby-forum.com/t/whats-the-most-restful-approach-here/171882/3 "2009-07-10T22:54:50Z")

</div>

thanks Rob,

I also think this is the most simple approach but was really keen to  
get a 2nd opinion.

Gavin

On Jul 10, 7:59 pm, Rob B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
