在routes.rb
中,如果有如下的一行代码:
map.resources :users
生成的路由可能是这样的:
users GET /users(.:format) {:controller=>"users", :action=>"index"}
POST /users(.:format) {:controller=>"users", :action=>"create"}
new_user GET /users/new(.:format) {:controller=>"users", :action=>"new"}
edit_user GET /users/:id/edit(.:format) {:controller=>"users", :action=>"edit"}
user GET /users/:id(.:format) {:controller=>"users", :action=>"show"}
PUT /users/:id(.:format) {:controller=>"users", :action=>"update"}
DELETE /users/:id(.:format) {:controller=>"users", :action=>"destroy"}
有没有办法将POST /users
映射的默认HTTP方法更改为使用PUT
方法,而不是现在的{:controller=>"users", :action=>"create"}
?
rake routes
会生成类似以下内容:
users GET /users(.:format) {:controller=>"users", :action=>"index"}
PUT /users(.:format) {:controller=>"users", :action=>"create"}
new_user GET /users/new(.:format) {:controller=>"users", :action=>"new"}
edit_user GET /users/:id/edit(.:format) {:controller=>"users", :action=>"edit"}
user GET /users/:id(.:format) {:controller=>"users", :action=>"show"}
PUT /users/:id(.:format) {:controller=>"users", :action=>"update"}
DELETE /users/:id(.:format) {:controller=>"users", :action=>"destroy"}
我知道这对于RESTful路由来说可能不正确,我只是想知道是否可以更改这些路由使用的HTTP方法。