Question

I understand why a Rails index method would use the plural form of a resource - we're showing all projects, for example.

And I understand why the show method would use the singular form - we only want to see one project, with a particular ID.

But I don't understand why new and create would use the plural. Is there a way to create more than one project at a time? Is there some other reasoning for using the plural here that someone could explain?

Was it helpful?

Solution

New and Create aren't plural, in the way I think about REST. Instead, I think about it like:

whatever.com is your base domain, and whatever.com/books means that you have a collection of resources each named book. The collection itself is named books.

So, when you want to create a new book, you are asking the collection for the information needed to create a new book. This becomes /books/new

When you actually create the book, you are posting information to /books. The HTTP verb is POST, so when you POST to your collection, you execute the create action.

This looks like a good starting point on REST.

OTHER TIPS

I thought they were always plural. Scroll down a bit on this page for an example of the routes generated by resources :photos

Whether you're GETting a single resource or POSTing to the collection, you're still in the domain of photos. So, search the domain of photos given an id, POST a new photo to the domain of photos, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top