CanCan - Access denied - Way to make CanCan Specify in the LOG Why?

橙三吉。 提交于 2019-12-05 23:59:27

问题


I'm working to implement CanCan. For some reason CanCan keeps giving me Access Denied when I try to get specific about model permissions. And I can't figure out why.

Is there a way to get CanCan to be specific, perhaps in the logs or in development about Why Access is denied? something like, No Read Ability to XXX Model.

That would be helpful for debugging.

Thanks


回答1:


You can add a rescue_from block in ApplicationController to handle CanCan exceptions and set your custom error message there. See the CanCan docs for a detailed explanation.




回答2:


You can add some output in your Ability model and check after what can or cannot your ability failed.

Or you can add a debugger session in start of you ability class.




回答3:


You can do:

# in ApplicationController
rescue_from CanCan::AccessDenied do |exception|
  Rails.logger.debug "Access denied on #{exception.action} #{exception.subject.inspect}"
  # ...
end

More info on the project's homepage: https://github.com/ryanb/cancan/wiki/Debugging-Abilities



来源:https://stackoverflow.com/questions/4089219/cancan-access-denied-way-to-make-cancan-specify-in-the-log-why

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