nowk
12/11/2011 - 10:30 PM

Devise + Declarative Authorization multi session/role use

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