Skip to content

Instantly share code, notes, and snippets.

@nowk
Created December 11, 2011 22:30
Show Gist options
  • Save nowk/1463173 to your computer and use it in GitHub Desktop.
Save nowk/1463173 to your computer and use it in GitHub Desktop.
Devise + Declarative Authorization multi session/role use
module AdminSetup
def self.included(base)
base.send :include, InstanceMethods
end
module InstanceMethods
protected
def declarative_devise_scope
:admin
end
end
end
class ApplicationController < ActionController::Base
protect_from_forgery
protected
def declarative_devise_scope
:user
end
def authorize_as
__send__ "current_#{declarative_devise_scope.to_s}"
end
def set_current_user
Authorization.current_user = authorize_as
end
before_filter :set_current_user
filter_access_to :all # this must be after, for multi-session admin/user login
end
class Admin::DashboardController < ApplicationController
include AdminSetup
def index
# /
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment