This time, I will introduce a method to restrict the transition so that users who are not logged in can only transition to the specified page.
Users who are not logged in can only transition to the index and show pages, and if they try to transition to the new page or edit page, they will be forced to transition to the index page.
Code that is used repeatedly in the controller is made into a method under private. By performing the following processing, if you try to transition to a page other than the index and show pages while the user is not logged in, you will be forced to transition to the index page.
class PracticeController < ApplicationController before_action :move_to_index, except: [:index, :show] ~abridgement~ private def move_to_index redirect_to action: :index unless user_signed_in? end