Let's me describe scenario.
I have 2 model, User and Organization, for user authorization and authentication with CanCan and Devise.
User belongs to an organization and Organization has many user.
Each user has a role (admin, power_user or default_user) which defined ability in cancan.
- Admin role can manage all organization and user data.
- Power user role can manage user within the same organization.
- Default user role can't access rails_admin can only just login or delete themselves.
The problem is when I try to create new user using Power user role it won't show any option for Organization in dropdown.
When using admin role it working well.
Here is my CanCan ability.
def admin_ability(user)
can :manage, User
can :manage, Organization
can :access, :rails_admin # grant access to rails_admin
can :dashboard # grant access to the dashboard
end
def poweruser_ability(user)
cannot :manage, User, role: Role.admin_role
can :access, :rails_admin # grant access to rails_admin
can :dashboard # grant access to the dashboard
end
def user_ability(user)
end
Do you have any idea to work arround this problem?
Thank you.