CanCan::Ability where is the current_user method defined?

浪子不回头ぞ 提交于 2019-12-04 05:45:43

问题


Pretty much what I have mentioned in the title. I am using CanCan::Ability in my code to check permissions and abilities. It expects a current_user method to be defined. I am guessing it comes from devise (but not sure), and I wish to override it. Whats the best way to do that?


回答1:


It's found here in the source code. It's nothing to do with devise, though. The documentation is found above the method and describes overwriting it.




回答2:


current_user is implemented by devise in this eval'ed block (which, I believe is called indirectly by the devise_for(:user) in your config/routes.rb). If you want to override it, you should be able to define your own current_user method in your ApplicationController.



来源:https://stackoverflow.com/questions/12461347/cancanability-where-is-the-current-user-method-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!