Rolify: Get list of users assigned to a specific resource

By Deepanshu Goyal

I have assigned roles to users with resource Project

class User < ApplicationRecord
  rolify
end
class Project < ApplicationRecord
  resourcify
end

Now what I need is to access the users with any role assigned with a specific project.

There is no direct way in the documentation. The closest being: User.with_any_role(:user, :admin) but I cannot mention the resource in it.

And the other is: Project.with_roles([:admin, :user], current_user) but with_roles is not working with the USER model.

Is there any way to fetch users of a specific project only?

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273