Skip to content

Instantly share code, notes, and snippets.

@jalcine
Created October 13, 2012 00:36
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 jalcine/3882595 to your computer and use it in GitHub Desktop.
Save jalcine/3882595 to your computer and use it in GitHub Desktop.
Role Hierarchy in Rolify
# A lot of times, you might have multiple roles in your User model.
# Also, at times, you keep the administrative users and regular users (if you may) in the
# same model. This can lead to a few issues when attempting to assign multiple roles
# to users.
# A potential use-case could be as follows:
# file: app/controllers/foo_controller.rb
magic_user = User.find_by_foo(:bar)
case magic_user.primary_role
when :administrator
flash[:info] = "With great power comes great responsibility."
when :street_fighter
flash[:info] = "Hadouken!"
....
end
# The concept of a primary role could allow users to have multiple
# roles while still maintaining a list of the many roles that one user
# can have.
# If desired, this can be configured by a toggle (if that's feasible).
# file: config/initializers/rolify.rb
Rolify.config do | config |
config.allow_primary_roles = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment