Infos :
- Rails 4.0.2
- CanCan (1.6.10)
- Devise (3.2.4)
- ActiveAdmin (1.0.0.pre)
I'm trying to use cancan gem to manage authorizations access my backoffice (activeadmin). I followed here: the tutorial http://www.activeadmin.info/docs/13-authorization-adapter.html#using_the_cancan_adapter
The thing is the "user" variable is always nil in the cancan's initializer, even when there is a user logged in.
Here is my code:
class Ability
include CanCan::Ability
def initialize(user)
return unless user
if user.has_operator_role? :active_admin
can :manage, ActiveAdmin::Page, name: 'Dashboard'
end
end
I put a debugger before the "return unless user" line and the "user" variable is always nil. In the views, the "current_user" variable is correctly set BTW.
Thanks for your help!
EDIT
I also tried with CanCanCan gem but it doesn't solve the problem!