I am looking into a Rails plugin, and it seems that to create a user, the HTML form says
<form action="/users" method="post">
and if I do a
rake routes
it says:
users GET /users(.:format) {:controller=>"users", :action=>"index"}
POST /users(.:format) {:controller=>"users", :action=>"create"}
so looks like a standard is that a GET to /controller_name
is to perform the index
action, while a POST is to per开发者_如何转开发form the create
action? Is this almost the 100% standard? Is there any exception?
Ther answer is NO
Rails routs are as flexible as you can imagine.
BUT. Rails loves REST style. You can read some wiki http://en.wikipedia.org/wiki/Representational_State_Transfer
REST like CRUD: http://en.wikipedia.org/wiki/Create,_read,_update_and_delete
So. We have got convention about resources. We can:
- READ list of resources:
GET /resources
- READ resource:
GET /resources/:id
- CREATE new resource:
POST /resources
- UPDATE resource:
PUT /resources/:id
- DELETE resource:
DELETE /resources/:id
- READ resource for edit:
GET /resources/:id/edit
- READ for creating:
GET /resources/new
This is a basis of REST.
This is the default when using Rails' resourceful routes. You can of course override this default in many ways, as described in this guide, but you should only do so with good reason.
精彩评论