使用delete设计与其他路由冲突

时间:2015-06-10 21:57:45

标签: ruby-on-rails ruby-on-rails-4 devise rails-routing

我的这两条路线在我的应用程序中有冲突

Function.prototype.bind

我的路线文件的相应部分如下

destroy_users DELETE /users/:id(.:format)                  users#destroy
destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy

当我尝试使用以下链接销毁会话时

match '/users/:id', to: 'users#destroy', :via => :delete, :as =>:destroy_users
devise_for :users
resources :users

它尝试导航到以下路线 本地主机:3000 /用户/ SIGN_OUT

这是我的UserController,并尝试运行destroy方法,将sign_out作为参数传递而不是路由

<li><%= link_to "Sign out", destroy_user_session_path, method: "delete" %></li>

我的路由文件中的第一行是允许在UserController中删除单个用户,这是destroy方法。这必须放在devise_for之前,否则它试图使用DELETE路由到devise的edit_user_registration_path。现在它似乎覆盖了devise destroy_user_session_path

我不确定如何解决这个问题,我们将不胜感激

1 个答案:

答案 0 :(得分:0)

通常,我认为Arrays.asList("a", "b", "c").forEach( ((Consumer<String>) s -> System.out.println(s + "1")) .andThen(s->System.out.println(s + "2")) .andThen(s -> System.out.println(s + "3")) ); 会创建以下路线

devise_for :users

使用您获得的路线

                  Prefix Verb   URI Pattern                    Controller#Action
        new_user_session GET    /users/sign_in(.:format)       devise/sessions#new
            user_session POST   /users/sign_in(.:format)       devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy
           user_password POST   /users/password(.:format)      devise/passwords#create
       new_user_password GET    /users/password/new(.:format)  devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
                         PATCH  /users/password(.:format)      devise/passwords#update
                         PUT    /users/password(.:format)      devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)        devise/registrations#cancel
       user_registration POST   /users(.:format)               devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)       devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)          devise/registrations#edit
                         PATCH  /users(.:format)               devise/registrations#update
                         PUT    /users(.:format)               devise/registrations#update
                         DELETE /users(.:format)               devise/registrations#destroy

删除第一条 Prefix Verb URI Pattern Controller#Action destroy_users DELETE /users/:id(.:format) users#destroy <--- oops this should be below all the other routes new_user_session GET /users/sign_in(.:format) devise/sessions#new user_session POST /users/sign_in(.:format) devise/sessions#create destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy user_password POST /users/password(.:format) devise/passwords#create new_user_password GET /users/password/new(.:format) devise/passwords#new edit_user_password GET /users/password/edit(.:format) devise/passwords#edit PATCH /users/password(.:format) devise/passwords#update PUT /users/password(.:format) devise/passwords#update cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel user_registration POST /users(.:format) devise/registrations#create new_user_registration GET /users/sign_up(.:format) devise/registrations#new edit_user_registration GET /users/edit(.:format) devise/registrations#edit PATCH /users(.:format) devise/registrations#update PUT /users(.:format) devise/registrations#update DELETE /users(.:format) devise/registrations#destroy users GET /users(.:format) users#index POST /users(.:format) users#create new_user GET /users/new(.:format) users#new edit_user GET /users/:id/edit(.:format) users#edit user GET /users/:id(.:format) users#show PATCH /users/:id(.:format) users#update PUT /users/:id(.:format) users#update DELETE /users/:id(.:format) users#destroy <--- notice it typically would be 路线可以帮助您......或者您可以将其移至match下方。您应该跳过使用resources :users创建destroy