Rolify not have a particular role check condition in rails

385 Views Asked by At

I am using rolify for assign various roles to a user. Like admin, professor, student, staff.

I am to define a condition where I have to specify that this particular condition is true for only those users who are not admin.

I know how to check if a user is admin

u=User.first
u.has_role?(:admin)

But I not able to figure out how to check the user doesn't have the role of admin?

Please help me get a solution to this.

1

There are 1 best solutions below

1
gabrimac On BEST ANSWER

you can implement this method in user model, this means that the user has other roles but not admin

def has_not_role?(role)
  roles.where.not(name: role).exists?
end