是的,您可以将它们分组到collection
嵌套在块中的块中resources :posts
,如下所示
resources :posts, :except => :destroy do
collection do
match 'page/:page' => 'posts#page'
match 'delete/:id' => 'posts#delete'
match 'undelete/:id' => 'posts#undelete'
match 'hide/:id' => 'posts#hide'
match 'unhide/:id' => 'posts#unhide'
end
end
这些路由虽然不是很 RESTful。我可能会建议以下内容
resources :posts, :except => :destroy do
member do
get 'page/:page' => 'posts#page'
delete 'delete' => 'posts#delete'
put 'undelete' => 'posts#undelete'
put 'hide' => 'posts#hide'
put 'unhide' => 'posts#unhide'
end
end
这会创建更清晰的路线,同时仍指向相同的控制器/动作。您将不得不修改您的应用程序以稍微不同地指向正确的路由,以支持这种更可接受的行为。
GET /posts/:id/page/:page(.:format) posts#page
delete_post DELETE /posts/:id/delete(.:format) posts#delete
undelete_post PUT /posts/:id/undelete(.:format) posts#undelete
hide_post PUT /posts/:id/hide(.:format) posts#hide
unhide_post PUT /posts/:id/unhide(.:format) posts#unhide
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PUT /posts/:id(.:format) posts#update