如何将相同的动词路由到资源上的不同操作?

时间:2015-08-10 13:53:33

标签: ruby-on-rails ruby-on-rails-3 rails-routing

我有一个task_list模型,它有一些像archive和destroy这样的动作。我想像这样路由它们:

resources :task_lists, only: [:create, :update] do
    member do
      delete '' => 'task_lists#archive'
      delete 'destroy' => 'task_lists#destroy'
    end
end

rake routes为两者提供相同的路线。

             DELETE   /api/0.0/task_lists/:id(.:format)    task_lists#archive {:format=>:json}
   task_list DELETE   /api/0.0/task_lists/:id(.:format)    task_lists#destroy {:format=>:json}

所以我该怎么办?

谢谢!

1 个答案:

答案 0 :(得分:0)

试试这个。

delete 'task_lists/:id/destroy(.:format)', :to => 'task_lists#destroy', :as => :destroy_task

delete 'task_lists/:id(.:format)', :to => 'task_lists#archive', :as => :archive_task