Skip to content

Instantly share code, notes, and snippets.

@jgautsch
Created April 12, 2013 15:54
Show Gist options
  • Save jgautsch/5373034 to your computer and use it in GitHub Desktop.
Save jgautsch/5373034 to your computer and use it in GitHub Desktop.
LOGAN Center 2/3 Code example
############################################
# Application Controller - CanCan
############################################
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_path, :alert => exception.message
end
def after_sign_in_path_for(resource)
case current_user.roles.first.name
when 'admin'
users_path
when 'applicant'
content_applicant_path
when 'employee'
content_employee_path
when 'client'
content_client_path
when 'HRadmin'
content_hradmin_path
else
root_path
end
end
end
############################################
# Content Controller - Rolify and Devise
############################################
class ContentController < ApplicationController
before_filter :authenticate_user!
def applicant
authorize! :view, :applicant, :message => 'Access limited to applicants.'
end
def employee
authorize! :view, :employee, :message => 'Access limited to current employees.'
end
def client
authorize! :view, :client, :message => 'Access limited to current clients.'
end
end
############################################
# Abilities/Roles - CanCan
############################################
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.has_role? :admin
can :manage, :all
else
can :view, :employee if user.has_role? :employee
can :view, :applicant if user.has_role? :applicant
can :view, :client if user.has_role? :client
can :view, :hradmin if user.has_role? :hradmin
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment