chaps-io / access-granted

Multi-role and whitelist based authorization gem for Rails (and not only Rails!)
MIT License
774 stars 41 forks source link

Raise exception when current_policy is not defined #3

Closed robuye closed 10 years ago

robuye commented 10 years ago

Controller#current_policy was depending on either defining Policy class with top level namespace or overriding the method. If none of it has been done the stacktrace was very confusing, ie:

     NameError:
       uninitialized constant Policy
bundler/gems/access-granted-9a2655e7f6f9/lib/access-granted/controller_methods.rb:4:in
`current_policy'
bundler/gems/access-granted-9a2655e7f6f9/lib/access-granted/controller_methods.rb:12:in
`can?'
ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/abstract_controller/helpers.rb:53:in
`can?'

Now the error is:

     NotImplementedError:
       You must implement #current_policy in ActionController.