Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# If you know of a better way to do this, please fork the gist!
def query_by_role(object, role_name)
corresponding_role_ids = object.accepted_roles.all(:conditions => { :name => role_name }).map(&:id)
# this will now return all users that have +role_name+ on +object+
User.all(:include => :roles, :conditions => [' IN (?)', corresponding_role_ids])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment