Say I have 4 roles: user, agent, admin, superadmin.
Where each role has subsequently more permissions on all objects in my app.
I am using Rolify, CanCan & Devise.
What I would like to do is, whenever I want to enable something – say:
<%= link_to "Create New User", new_user_registration_path if current_user.has_role? :superadmin %>
I would like for that link to show if the person is either an admin or a superadmin. I know I could simply just do an || – but that doesn’t seem very DRY, especially since I will have to do current_user.has_role? :superadmin || current_user.has_role? :admin.
Imagine there are some links/assets that I want agent, admin & superadmin to have access to.
How do I do this in a DRY way?
Why do u check roles instead of checking a permissions? As I know cancan support
can?andcannot?methods which can help in your situation. You should write something like thisUsefull link about this feature