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

3

7

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

Santinasantini answered 3/11, 2010 at 16:25 Comment(0)
D
5

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.

Deccan answered 3/11, 2010 at 20:49 Comment(0)
O
1

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.

Oniskey answered 3/11, 2010 at 17:6 Comment(0)
T
0

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

Tumble answered 10/11, 2015 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.