Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

overwrite devise current_patient method

I have current_patient which has been created by devise. i have used this in a lot of places around my app.

However i now want to add a condition into this method (to check for current_admin aswell). So i was thinking of overwriting the current_patient method in the application controller.

So basically the method would look like:

def current_patient
 current_patient || current_admin
end

Im going for this approach rather than creating a new method called current_patient_or_admin for example, because i don't want to have to replace every place where current_patient is being called.

However i'm aware that the above snippet will not work as it will create an infinite loop, so i was wondering if anyone has any idea about how to do this? I have also tried using an alias_method but i believe that it will cause the same problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...