There is a method in the application controller called current_ability , you can just overwrite it.
Change current documentation
It will look something like this.
def current_ability @current_ability ||= Ability.new(current_user) end
But you can change it to
def current_ability if current_doctor @current_ability ||= Ability.new(current_doctor) else @current_ability ||= Ability.new(current_patient) end end
This will allow you to initialize the method in app / models / .rb ability to get either current_patient or current_doctor depending on the case. You can customize it to look something like this.
class Ability include CanCan::Ability def initialize(resource) if resource.class == Patient can, Read Something can, Edit Other . . . else can, Read Something can, Edit Other . . . end . . .
I hope this help, you can also see cancan Full document
source share