[RUBY] [Note] Summary of rails login function using devise ①

I will summarize what I understood about the login function using devise.

I referred to the following site. Reference site: [Ruby on Rails] How to log in with only name and password using devise of gem

I hope it helps such a person

About routing (route.rb)

Routing to the following routes.rb


Rails.application.routes.draw do
  devise_for :users, controllers: {
    sessions: 'users/sessions',
    registrations: 'users/registrations',
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

  root 'homes#top'
  get 'mypage', to: 'homes#about'
  # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html

Let's check what kind of routing is done with the following command.

$ rails routes

Execution result ↓

                               Prefix Verb   URI Pattern                                                                              Controller#Action
                     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
                    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)                                                                  users/registrations#cancel
                new_user_registration GET    /users/sign_up(.:format)                                                                 users/registrations#new
               edit_user_registration GET    /users/edit(.:format)                                                                    users/registrations#edit
                    user_registration PATCH  /users(.:format)                                                                         users/registrations#update
                                      PUT    /users(.:format)                                                                         users/registrations#update
                                      DELETE /users(.:format)                                                                         users/registrations#destroy
                                      POST   /users(.:format)                                                                         users/registrations#create
                                 root GET    /                                                                                        homes#top
                               mypage GET    /mypage(.:format)                                                                        homes#about
        rails_postmark_inbound_emails POST   /rails/action_mailbox/postmark/inbound_emails(.:format)                                  action_mailbox/ingresses/postmark/inbound_emails#create
           rails_relay_inbound_emails POST   /rails/action_mailbox/relay/inbound_emails(.:format)                                     action_mailbox/ingresses/relay/inbound_emails#create
        rails_sendgrid_inbound_emails POST   /rails/action_mailbox/sendgrid/inbound_emails(.:format)                                  action_mailbox/ingresses/sendgrid/inbound_emails#create
  rails_mandrill_inbound_health_check GET    /rails/action_mailbox/mandrill/inbound_emails(.:format)                                  action_mailbox/ingresses/mandrill/inbound_emails#health_check
        rails_mandrill_inbound_emails POST   /rails/action_mailbox/mandrill/inbound_emails(.:format)                                  action_mailbox/ingresses/mandrill/inbound_emails#create
         rails_mailgun_inbound_emails POST   /rails/action_mailbox/mailgun/inbound_emails/mime(.:format)                              action_mailbox/ingresses/mailgun/inbound_emails#create
       rails_conductor_inbound_emails GET    /rails/conductor/action_mailbox/inbound_emails(.:format)                                 rails/conductor/action_mailbox/inbound_emails#index
                                      POST   /rails/conductor/action_mailbox/inbound_emails(.:format)                                 rails/conductor/action_mailbox/inbound_emails#create
    new_rails_conductor_inbound_email GET    /rails/conductor/action_mailbox/inbound_emails/new(.:format)                             rails/conductor/action_mailbox/inbound_emails#new
   edit_rails_conductor_inbound_email GET    /rails/conductor/action_mailbox/inbound_emails/:id/edit(.:format)                        rails/conductor/action_mailbox/inbound_emails#edit
        rails_conductor_inbound_email GET    /rails/conductor/action_mailbox/inbound_emails/:id(.:format)                             rails/conductor/action_mailbox/inbound_emails#show
                                      PATCH  /rails/conductor/action_mailbox/inbound_emails/:id(.:format)                             rails/conductor/action_mailbox/inbound_emails#update
                                      PUT    /rails/conductor/action_mailbox/inbound_emails/:id(.:format)                             rails/conductor/action_mailbox/inbound_emails#update
                                      DELETE /rails/conductor/action_mailbox/inbound_emails/:id(.:format)                             rails/conductor/action_mailbox/inbound_emails#destroy
rails_conductor_inbound_email_reroute POST   /rails/conductor/action_mailbox/:inbound_email_id/reroute(.:format)                      rails/conductor/action_mailbox/reroutes#create
                   rails_service_blob GET    /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
            rails_blob_representation GET    /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
                   rails_disk_service GET    /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
            update_rails_disk_service PUT    /rails/active_storage/disk/:encoded_token(.:format)                                      active_storage/disk#update
                 rails_direct_uploads POST   /rails/active_storage/direct_uploads(.:format)                                           active_storage/direct_uploads#create

About view

First, the view files that can be created under users are as follows.

About controller


New registration behavior

1.1. Connect to localhost: 3000

1.2. Of routes.rb

root GET    /  homes#top

Refer to to display top-> views/homes/top.html.erb of home_controller.rb.

1.3. Click new registration

1.4. See the following line in routes.rb by<% = link_to'new registration', new_user_registration_path%>in top.html.erb

new_user_registration GET    /users/sign_up(.:format)  users/registrations#new

Since there is no new in users/registrations_controller.rb, it displays users/registrations/new.html.erb without executing anything.

1.5. Enter name, email, password, confirmation password and click New Registration.


<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>

I couldn't find this part by examining it. I will investigate in detail next time.

1.7. The information entered in the DB is registered and mypage.html.erb is displayed.

Recommended Posts

[Note] Summary of rails login function using devise ①
Implementation of Ruby on Rails login function (devise edition)
[Rails] Function restrictions in devise (login / logout)
Implementation of user authentication function using devise (2)
Rails Addition of easy and easy login function
Implementation of user authentication function using devise (3)
[Rails] Implementation of new registration function in wizard format using devise
[Rails] Implementation of search function using gem's ransack
Implementation of Ruby on Rails login function (Session)
[Rails 6] Implementation of inquiry function using Action Mailer
[Rails] Implementation of image enlargement function using lightbox2
Story of implementing login function using gem sorcery
Summary of using FragmentArgs
Summary of using DBFlow
Ruby on Rails <2021> Implementation of simple login function (form_with)
[Rails] Test of star evaluation function using Raty [Rspec]
[Rails] Implementation of multi-layer category function using ancestry "Preparation"
Rails application guest login function implemented (devise not used)
[Rails] Implementation of multi-layer category function using ancestry "seed"
[Rails] Initial setting of user-created login with devise, devise_token_auth
Rails tutorial (6th edition) Background operation of login function
Addition of guest login function
[Rails] Introduction of devise Basics
Search function using [rails] ransack
[Rails 6] Implementation of search function
[Rails] Implementation of category function
Login function implementation with rails
Ajax bookmark function using Rails
[Rails] Implementation of tutorial function
[Rails] Implementation of like function
[Rails] Implementation of multi-layer category function using ancestry "Editing form"
[Rails] Register by attribute of the same model using Devise
[Rails] Implementation of multi-layer category function using ancestry "Creation form"
A note about the seed function of Ruby on Rails
[Rails] Implementation of tagging function using intermediate table (without Gem)
[Rails Struggle/Rails Tutorial] Summary of Rails Tutorial Chapter 2
[Rails] Implementation of CSV import function
[Rails] Asynchronous implementation of like function
Summary of rails validation (for myself)
[Rails] How to use devise (Note)
[Rails] Implementation of image preview function
[Rails] Tag management function (using acts-as-taggable-on)
Kaminari --Added pagination function of Rails
[Rails] About implementation of like function
[Rails] Implementation of user withdrawal function
[Rails] Implementation of CSV export function
[Rails] Summary of complicated routing configurations
Implement simple login function in Rails
Summary of devise controller initial state
Summary of object-oriented programming using Java
[Rails] Implementation of coupon function (with automatic deletion function using batch processing)
[Rails] Implementation of tag function using acts-as-taggable-on and tag input completion function using tag-it
[Rails] Addition of Ruby On Rails comment function
[Rails] Create an evaluation function using raty.js
[Rails Struggle/Rails Tutorial] Summary of Heroku commands
[Rails] I will explain the implementation procedure of the follow function using form_with.
Creating a user authentication function using devise
Rails [For beginners] Implementation of comment function
Make a login function with Rails anyway
[Rails 6] Implementation of SNS (Twitter) sharing function
[Rails] devise