1

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?

Nathan Long
  • 122,748
  • 97
  • 336
  • 451

2 Answers2

2

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.

Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
  • 1
    Thanks. It still feels to me like I would want to say `/book/new` when creating one book. It's not a big deal, but since the whole purpose of pluralization is to make things more like plain English, it's odd to have to say something that feels like "I want to create a new books" instead of "a new book." – Nathan Long Dec 20 '10 at 15:15
  • 1
    reading /book for me automatically mewns that i'm refering some specific already existing book therefore /book/new doesn't make sense from that point of view and /books/new makes perfect sense – keymone Dec 20 '10 at 15:50
1

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.

Samo
  • 8,202
  • 13
  • 58
  • 95