Cela peut arriver si vous créez users_controller et que vous devez faire attention.
Pas de collision
route.rb
Rails.application.routes.draw do
resources :profiles
devise_for :users, controllers: { sessions: 'users/sessions'}
resources :users
root to: "home#home"
end
new_user_session GET /users/sign_in(.:format) users/sessions#new
user_session POST /users/sign_in(.:format) users/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) users/sessions#destroy
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
Une collision se produit
route.rb
Rails.application.routes.draw do
resources :profiles
resources :users
devise_for :users, controllers: { sessions: 'users/sessions'}
root to: "home#home"
end
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
new_user_session GET /users/sign_in(.:format) users/sessions#new
user_session POST /users/sign_in(.:format) users/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) users/sessions#destroy
ʻUsers /: id contient ʻusers / sign_in
, et lors de la transition vers users / sign_in, il est reconnu comme users / id et fait référence à ʻusers_controller`.
Le routage étant référencé dans l'ordre à partir du haut, cela peut être évité si users / sign_in est décrit ci-dessus users /: id.
Recommended Posts