Ruby on rails 使用delete设计与其他路由冲突的路由
在我的应用程序中,我有两条相互冲突的路线Ruby on rails 使用delete设计与其他路由冲突的路由,ruby-on-rails,ruby-on-rails-4,devise,rails-routing,Ruby On Rails,Ruby On Rails 4,Devise,Rails Routing,在我的应用程序中,我有两条相互冲突的路线 destroy_users DELETE /users/:id(.:format) users#destroy destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy 我的routes文件的相应部分如下所示 match '/users/:id', to: 'users#destroy', :via =>
destroy_users DELETE /users/:id(.:format) users#destroy
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
我的routes文件的相应部分如下所示
match '/users/:id', to: 'users#destroy', :via => :delete, :as =>:destroy_users
devise_for :users
resources :users
当我尝试使用以下链接销毁会话时
<li><%= link_to "Sign out", destroy_user_session_path, method: "delete" %></li>
我的routes文件中的第一行是允许在UserController中删除单个用户,这是销毁方法。这必须放在设备之前,否则它试图使用DELETE路由到设备的编辑用户注册路径。现在它似乎覆盖了designe destroy\u user\u session\u路径
我不知道如何解决这个问题,任何建议都会受到欢迎。通常,我认为
为用户设计创建以下路径
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
前缀动词URI模式控制器#操作
销毁用户删除/users/:id(:format)用户销毁我不确定发生了什么,我需要将“/users/:id”匹配到:'users#destroy',:via=>:DELETE,:as=>:destroy\u用户。一旦我删除了它,并将我的删除路径设置回用户路径,一切又开始为我工作了。我一直在切换到Desive和cancancan,在我的重构过程中,我一定犯了一个错误,然后投入了一个黑客来修复这个错误
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