[Rails 5] How to display the password change screen when using devise

Overview

When I introduced devise in Rails5, I had a problem that the password change screen generated by devise could not be displayed properly, so I will leave it as a memorandum.

What you can see in this article

--How to display the password change screen before and after logging in to devise

Premise


Usage environment
ruby 2.5.7 rails 5.2.4

Display method

Check devise routing

After installing devise, if you check the routing using the "rails routes" command on the console, it will be displayed in the following form.

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

At this time, the routing for displaying the password change screen is

edit_user_password GET    /users/password/edit(.:format)  

It may seem like (I did), but there is actually another routing for the change screen. that is

edit_user_registration GET    /users/edit(.:format)

is. The difference between the two is

edit_user_password GET    /users/password/edit(.:format)  #Password change screen before login
edit_user_registration GET    /users/edit(.:format)  #Password change screen after login

... apparently ...

Let's use each correctly, such as specifying the path in "link_to" (although I feel that I basically use only the one after login).

Recommended Posts

[Rails 5] How to display the password change screen when using devise
How to set the display time to Japan time in Rails
[Ruby on Rails] How to log in with only your name and password using the gem devise
[Rails] How to install devise
How to add characters to display when using link_to method
[Ruby on Rails] How to change the column name
[Rails] How to change the column name of the table
[Rails] Cancel / change the default password validation of devise
[Ruby on Rails] When logging in for the first time ・ How to split the screen in half using jQuery
[Rails] How to display an image in the view
[Rails] How to solve the error "undefined method` visit'" when using Capybara with Rspec
[Rails] How to display the weather forecast of the registered address in Japanese using OpenWeatherMap
How to set environment variables when using Payjp with Rails
[Rails] How to delete images uploaded by carrierwave (using devise)
[Rails] When the layout change of devise is not reflected
[Rails] How to display the list of posts by category
When you want to change the MySQL password of docker-compose
[Rails] How to display information stored in the database in view
[Rails] How to use gem "devise"
[Rails] How to use devise (Note)
[rails] How to display db information
[Rails] How to prevent screen transition
When changing user information using devise Settings on the edit screen when the password is not saved
[Swift] How to display when the quiz app answers correctly [Beginner]
[Rails 6] How to create a dynamic form input screen using cocoon
[Rails] How to introduce kaminari with Slim and change the design
How to display products by category on the same list screen
[Rails] How to omit the display of the character string of the link_to method
[Rails] How to change the page title of the browser for each page
How to solve the unknown error when using slf4j in Java
How to write the view when Vue is introduced in Rails?
[Rails] How to convert the URI of the image sent by http to https when using Twitter API
How to change app name in rails
[Rails] How to upload images using Carrierwave
[Rails] How to display error messages individually
How to change the timezone on Ubuntu
Ransack sort_link How to change the color!
How to pass the value to another screen
How to implement image posting using rails
[Rails] How to use video_tag to display videos
[Rails] How to translate devise into Japanese
[Rails] How to handle data using enum
[Rails] I was addicted to the nginx settings when using Action Cable.
[Rails] About the error when displaying the screen due to the autofocus of the form
Gorigori beginners summarized how to operate the database using rails console Ntiunus
How to update user edits in Rails Devise without entering a password
[Rails] How to get the user information currently logged in with devise
[Rails] How to create a table, add a column, and change the column type
[Rails] How to pass validation such as password when executing update action
How to display the text entered in text_area in Rails with line breaks
[Ruby On Rails] How to search the contents of params using include?
[Rails] How to decide the destination by "rails routes"
[Rails] When I use form_with, the screen freezes! ??
[Rails] How to write when making a subquery
The road to Japaneseizing Rails devise error messages
[Ruby on Rails] How to display error messages
[Rails] How to create a graph using lazy_high_charts
How to implement the breadcrumb function using gretel
How to delete the database when recreating the application
[Rails] How to upload multiple images using Carrierwave
How to display the result of form input