开发者

Why does Rails use plurals for new and create?

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜