This can happen if you create users_controller and you need to be careful.
No 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
Collision occurs
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 contains ʻusers / sign_in
, and when transitioning to users / sign_in, it is recognized as users / id and refers to ʻusers_controller`.
Routing is referenced from top to bottom, so you can prevent this if users / sign_in is listed above users /: id.
Recommended Posts