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
Routing to the following routes.rb
app/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
end
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
First, the view files that can be created under users are as follows.
homes
top.html.erb
about.html.erb
I renamed the file to mypage-> about.
users
confirmations/new.html.erb
mailer/confirmation_instructions.html.erb
mailer/email_changed.html.erb
mailer/password_change.html.erb
mailer/reset_password_instructions.html.erb
mailer/unlock_instructions.html.erb
passwords/edit.html.erb
passwords/new.html.erb
registrations/edit.html.erb
registrations/new.html.erb
sessions/new.html.erb
shared/_error_message.html.erb
shared/_links.html.erb
unlocks/new.html.erb
homes_controller.rb
confirmations_controller.rb
omniauth_callbacks_controller.rb
passwords_controller.rb
registrations_controller.rb
sessions_controller.rb
unlocks_controller.rb
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.
1.6.
<%= 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