Question

If I've got a number of roles which can all be scoped to the same resource (can be :administrator or :staff of an individual Agency instance), is there a single method which will return all of those roles, if I have a user and an agency?

Specifically-

User.rb
  rolify

Agency.rb
  resourcify # roles of :agent and :administrator exist on this resource

I'm looking for a single-method equivalent of @user.has_roles_for? @agency which will return true if the user has a role which points at that agency. Currently, I'm using (@user.roles & @agency.roles).eql? [] to check if this is the case, but hopefully there's a cleaner way to show it.

Was it helpful?

Solution

Unfortunately, currently there is no method that returns what you need. The closest is Agency.find_roles(nil, user), which will return the roles for the resource class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top