Skip to content

Instantly share code, notes, and snippets.

@Antiarchitect
Created May 11, 2012 08:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Antiarchitect/2658441 to your computer and use it in GitHub Desktop.
Save Antiarchitect/2658441 to your computer and use it in GitHub Desktop.
Single entry point for many scopes in Devise.
class ApplicationController < ActionController::Base
...
private
def after_sign_in_path_for(resource)
if current_administrator && current_administrator.is_admin?
[:admin, :admins]
else
root_path
end
end
def after_sign_out_path_for(resource)
case resource
when :administrator
[:new, :administrator, :session]
else
root_path
end
end
end
class Admin::BaseController < ApplicationController
respond_to :html, :json, :xml
before_filter :authenticate_admin!
private
def authenticate_admin!
authenticate_administrator!
unless current_administrator && current_administrator.is_admin?
respond_with current_administrator, location: after_sign_out_path_for(:administrator)
end
end
end
Myapp::Application.routes.draw do
devise_for :administrators
namespace :admin do
resources :admins
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment