问题描述
生成脚手架后,Rails让我能够POST到 items.xml
,这将创建一个新的项目
。 GET到 items.xml
只会列出所有内容。 Rails在哪里指定控制器中的哪个方法(分别为 create
或 index
)将根据类型进行调用我正在执行的操作?
After I generate a scaffold, Rails gives me the ability to POST to items.xml
which will create a new item
. A GET to items.xml
will simply list them all. Where does Rails specify which method in the controller (create
or index
, respectively) will be called, based on the type of action I am performing?
更具体地说,POST调用methodA但GET到同一个URL调用methodB。这指定在哪里? Rails在哪里决定调用控制器的 index
方法?
More specifically, POST calls methodA but GET to the same URL calls methodB. Where is this specified? Where does Rails make the determination to call the index
method of the controller?
推荐答案
我相信它是由指定的。以下是ya的列表:
I believe it's specified by REST. Here's a list for ya:
GET /items #=> index
GET /items/1 #=> show
GET /items/new #=> new
GET /items/1/edit #=> edit
PUT /items/1 #=> update
POST /items #=> create
DELETE /items/1 #=> destroy
编辑添加以获取配置/路由中的所有路由.rb,只需添加 map.resources:items
Edited to add to get all those routes, in config/routes.rb, simply add map.resources :items
这篇关于Rails POST,PUT,GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!