Skip to content

Instantly share code, notes, and snippets.

@hlxwell
Created September 1, 2014 16:08
Show Gist options
  • Save hlxwell/4d68db4c628537ceaefd to your computer and use it in GitHub Desktop.
Save hlxwell/4d68db4c628537ceaefd to your computer and use it in GitHub Desktop.
routes.rb level permission control
# Method 1 =============================================
class ProjectManagerChecker
def self.matches?(request)
request.env['warden'].user.role == 'project_manager'
end
end
# routes.rb
get '/' => 'project_managers#index', :constraints => ProjectManagerChecker
get '/' => 'clients#index'
# Method 2 =============================================
authenticated :user, ->(u) { u.has_role?(:manager) } do
root to: "managers#index", as: :manager_root
end
authenticated :user, ->(u) { u.has_role?(:employee) } do
root to: "employees#index", as: :employee_root
end
root to: "landing_page#index"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment