Created
October 13, 2012 00:36
-
-
Save jalcine/3882595 to your computer and use it in GitHub Desktop.
Role Hierarchy in Rolify
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
# 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