0
0

More than 3 years have passed since last update.

gem 'devise'に苦戦 プログラミング 37日目

Posted at

gem'devise'使う上で考慮すべきこと

1.URLかぶり

例えばdeviseをuserモデルに紐づけてinstallしたりすると以下のような(一部)routesが自動的にできます。

URLかぶりとは??
userのアカウント情報を表示させるusers/showを作ろうと、get "users/:id" => "users#show"をroutesの設定しました。そうするとそれまでできていたlogoutがうまくいかなくなりました。その原因として考えた結論が、users/:idとdeviseで設定した他のusers/~~~が被ってしまっているということです。(あっているかは定か)

usersはやめpages/:idにすることで解決しました。

                   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
                                 root GET    /   

2.いちいち編集ページなどは作らず既存のやつを使う方がいい

そしてviewも手順どうりに進めるとdeviseフォルダができます。deviseのフォルダにはメールアドレス情報やパスワードを変更するページもあるためいちいち編集ページを作る必要はありません。ただ名前を登録するところがないのが不便です。

0
0
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
0
0