Created
May 22, 2009 05:25
-
-
Save be9/115944 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 => ['roles.id IN (?)', corresponding_role_ids]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment