21
15

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 3 years have passed since last update.

【Rails】devise関連のルーティングまとめ

Posted at

deviseも便利な機能が故、それぞれ独自のメソッドが自動で生成してくれるルーティングについて、こんがらがってしまいます。
そんな同じお悩みの方はぜひ。

#devise_for

routes.rb
  devise_for :users
$ rails routes

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

###resources :usersとの比較

アクション名 リクエスト resources devise_for
new GET /users/new /users/sign_up(.:format)
edit GET /users/:id/edit /users/edit(.:format)
show GET /users/:id なし
index GET /users なし
create POST /users /users(.:format)
update PATCH / PUT /users /users(.:format)
destroy DELETE /users /users(.:format)

#devise_scope

routes.rb
  devise_scope :user do
    get 'signin' => 'devise_token_auth/sessions#new'
    post 'signin' => 'devise_token_auth/sessions#create'
    post 'signup' => 'users#create'
    put 'update' => 'users#update'
  end
$ rails routes

Prefix Verb   URI Pattern                  Controller#Action

signin GET    /signin(.:format)            devise_token_auth/sessions#new
       POST   /signin(.:format)            devise_token_auth/sessions#create
signup POST   /signup(.:format)            users#create
update PUT    /update(.:format)            users#update

#mount_devise_token_auth_for

routes.rb
  mount_devise_token_auth_for 'User', controllers: {
    registrations: 'users'
  }
$ rails routes

Prefix Verb   URI Pattern                  Controller#Action

signin GET    /signin(.:format)            devise_token_auth/sessions#new
       POST   /signin(.:format)            devise_token_auth/sessions#create
signup POST   /signup(.:format)            users#create
update PUT    /update(.:format)            users#update
21
15
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
21
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?