The original application is being created.
I have summarized what to do if you want to create multiple devises and set the path after routing after login.
First, assume that you have installed two or more devises, set devise_parameter_sanitizer, and so on.
If you haven't done so, please refer to here.
Individual settings of devise_parameter_sanitizer when creating two devises
http://localhost:3000/users/1/medicines
↑ I want to create a URL like this. I want to set the routine of the index of medicine whose id of users is 1.
I want to nest it, so I want to nest the routing. Use member do here.
What is member do? The id is attached to the routing.
resources :users do
member do
resources :medicines
end
end
Nest like this.
protected
def after_sign_in_path_for(*)
medicines_path(current_user.id)
end
I will explain.
Since the path will be changed after the login screen, describe it in /users/session_controller.rb. This time it is a path change in multiple devise, so write it in the users directory. If it is doctor devise, describe it in doctor / session_controller.rb.
after_sign_in_path_for is a method that specifies the path after signing in devise. (*) Is an argument that contains login information. The information received at the time of login is passed from the routing to the controller. Go to medicines_path with id as medicines_path (current_user.id) and determine which id current_user.id is from the received information.
I learned that it is important to set the path where it goes, whether it can pass arguments (information), or whether there is a place to disperse it.
Recommended Posts