1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails Deviseのルートを最小限コードでわかりやすくする。

Posted at

デフォルトでは、

routes.rb
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
   new_user_password GET    /users/password/new(.:format)  devise/passwords#new
  edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
       user_password PATCH  /users/password(.:format)      devise/passwords#update
                     PUT    /users/password(.:format)      devise/passwords#update
                     POST   /users/password(.:format)      devise/passwords#create

cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
user_registration PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
POST /users(.:format) devise/registrations#create

こう変更。

routes.rb
  devise_for :users,
         path: '',
         path_names: {sign_in: 'login', sign_out: 'logout', edit: 'profile', sign_up: 'registration'},
         controllers: {registrations: 'registrations'}

              Prefix Verb   URI Pattern              Controller#Action
    new_user_session GET    /login(.:format)         devise/sessions#new
        user_session POST   /login(.:format)         devise/sessions#create
destroy_user_session DELETE /logout(.:format)        devise/sessions#destroy
   new_user_password GET    /password/new(.:format)  devise/passwords#new
  edit_user_password GET    /password/edit(.:format) devise/passwords#edit
       user_password PATCH  /password(.:format)      devise/passwords#update
                     PUT    /password(.:format)      devise/passwords#update
                     POST   /password(.:format)      devise/passwords#create

cancel_user_registration GET /cancel(.:format) registrations#cancel
new_user_registration GET /registration(.:format) registrations#new
edit_user_registration GET /profile(.:format) registrations#edit
user_registration PATCH / registrations#update
PUT / registrations#update
DELETE / registrations#destroy
POST / registrations#create

スッキリ。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?