The authenticate_user! method is a devise helper method. When the authenticate_user! method is used, when the process is called, if the user is not logged in, that user is transitioned to the login screen. That is, the page to be displayed can be switched depending on the login status.
By calling before_action, you can transition to the login screen if you have not logged in before executing the action.
Write before_action: authenticate_user! At the beginning of the controller
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :authenticate_user!
end
After the description, if you are not logged in, the screen will change to the login screen.