Zequez
Zequez

Reputation: 3499

Should the SHOW action in a RESTful controller be always for only one resource?

So, I was thinking of doing something like this:

zones#show
/map/map_id/zones/zone_id

And this:

zones#index
/map/map_id/zones

But I would like the user to be able to display more than one zone at the same time (but not all of them), so I was thinking of something Reddit-like:

zones#show
/map/map_id/zones/zone_id_1+zone_id_2+zone_id_3

The ID would reach the controller as one parameter and then split between the "+" to make an array, nothing fancy in the routes.

Would this still be RESTful? Is this the best approach?

Upvotes: 0

Views: 321

Answers (1)

Mark Fraser
Mark Fraser

Reputation: 3198

The show RESTful action infers displaying one of a type of resource. The index action infers displaying a collection. As far as I know nothing in the latter implies that you must be showing every single instance (i.e. that it cannot be filtered...even if the filtering process only leaves only a small subset). So I would suggest using the index action and just showing the desired instances.

You might want to also check out this article:

http://www.informit.com/articles/article.aspx?p=1671632&seqNum=11

Upvotes: 2

Related Questions