我能想到的最佳解决方案是添加两个映射到#update 和#destroy 的新成员路由:
resources :posts do
member do
post :revise, :action => :update
post :annihilate, :action => :destroy
end
end
当你运行'rake routes'时添加了这些路由:
revise_post POST /posts/:id/revise(.:format) {:action=>"update", :controller=>"posts"}
annihilate_post POST /posts/:id/annihilate(.:format) {:action=>"destroy", :controller=>"posts"}
请注意,我最初尝试过这个:
resources :posts do
member do
post :update
post :destroy
end
end
希望它会创建这些路线:
update_post POST /posts/:id/update(.:format) {:action=>"update", :controller=>"posts"}
destroy_post POST /posts/:id/destroy(.:format) {:action=>"destroy", :controller=>"posts"}
但相反,它创建了:
POST /posts/:id(.:format) {:action=>"update", :controller=>"posts"}
POST /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"}
看起来它们是重叠的,你永远无法到达帖子#destroy。