Skip to content

Instantly share code, notes, and snippets.

@trak3r
Created January 8, 2009 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trak3r/44901 to your computer and use it in GitHub Desktop.
Save trak3r/44901 to your computer and use it in GitHub Desktop.
def has_role?(role)    
# if list isn't already assigned to something, create an array of the names of my roles
list ||= self.roles.map(&:name)    
# if list includes the string representation of the passed-in role [assumed to be the name] or if the list includes the string 'admin' [assumed to be the administrative role] return true
list.include?(role.to_s) || list.include?('admin')  
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment