Created
December 11, 2011 22:30
-
-
Save nowk/1463173 to your computer and use it in GitHub Desktop.
Devise + Declarative Authorization multi session/role use
This file contains hidden or 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
module AdminSetup | |
def self.included(base) | |
base.send :include, InstanceMethods | |
end | |
module InstanceMethods | |
protected | |
def declarative_devise_scope | |
:admin | |
end | |
end | |
end |
This file contains hidden or 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
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 |
This file contains hidden or 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
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