The original application is being created.
ruby '2.6.5' rails '6.0.0'
First, as a prerequisite, start with each devise's routing, model, controller, and view settings. Please refer to here for the above creation method.
Now, normally, if there is one devise for one application, use before_action in the application_controller.rb file to process devise_parameter_sanitizer.
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
private
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname])
end
end
In this way, you can allow a specific column when registering as a user.
This time I made two devises, user and doctor.
First of all, it's in the README of the repository, so I tried it, but it didn't work. I didn't know whether to create a file to inherit or to utilize an existing file.
As a result, there is an individual file app / controllers / users / registrations_controller.rb, so use that.
For User
app/controllers/users/registrations_controller.rb
For Doctor
app/controllers/doctors/registrations_controller.rb
Find the following description in the large number of commented outs in the user file.
app/controllers/users/registrations_controller.rb
# before_action :configure_sign_up_params, only: [:create]
Enable comments for. . ↓
app/controllers/users/registrations_controller.rb
before_action :configure_sign_up_params, only: [:create]
Now, when creating a user, Now that configure_sign_up_params is called In the same file, def configure_sign_up_params Comment out and enable it.
app/controllers/users/registrations_controller.rb
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname])
end
Then write the karamu you want to add to this (: sign_up, keys: [: nickname]) part.
app/controllers/users/registrations_controller.rb
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname, :password])
end
Doctor will do the same work. The file is app / controllers / doctors / registrations_controller.rb.
As some of you may have noticed, devise_parameter_sanitize is not written in app / controllers / application_controller.rb because it is not defined in the application controller and is called by before_action in an individual file.
When doing the above
TypeError
superclass mismatch for class DoctorController
class DoctorController < ApplicationController
I got an error. If you look closely, class DoctorController <ApplicationController is Doctor.
class DoctorController < ApplicationController
class DoctorsController < ApplicationController
Since it inherits from app / controllers / doctors / registrations_controller.rb, there is no "" s "", so describe it.
Rails has strict naming conventions, so be careful! !!
Recommended Posts