Created
January 30, 2014 13:11
-
-
Save deepakkumarnd/8708022 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
#lib/role_constraint.rb | |
class RoleConstraint | |
def initialize(*roles) | |
@roles = roles | |
end | |
def matches?(request) | |
@roles.include? request.env['warden'].user.try(:role) | |
end | |
end | |
#config/routes.rb | |
root :to => 'admin#index', :constraints => RoleConstraint.new(:admin) #matches this route when the current user is an admin | |
root :to => 'sites#index', :constraints => RoleConstraint.new(:user) #matches this route when the current user is an user | |
root :to => 'home#index' #matches this route when the above two matches don't pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment