Skip to content

Instantly share code, notes, and snippets.

@jonathansimmons
Created September 8, 2014 00:49
Show Gist options
  • Save jonathansimmons/19b3b026da6f03fa4ad6 to your computer and use it in GitHub Desktop.
Save jonathansimmons/19b3b026da6f03fa4ad6 to your computer and use it in GitHub Desktop.
A share login setup for two devise models.
Rails.application.routes.draw do
constraints subdomain: "admin" do
devise_for :admins, skip: [:sessions]
devise_scope :admin do
get '/login' => 'admins/sessions#new', as: :new_admin_session
post '/login' => 'admins/sessions#create', as: :admin_session
get '/logout' => 'admins/sessions#destroy', as: :destroy_admin_session
unauthenticated do
devise_scope :admin do
root to: redirect("/login"), :as => "unauthenticated_admin"
end
end
authenticated do
devise_scope :admin do
root to: "admins/sessions#new", :as => "authenticated_admin"
end
end
end
end
devise_for :users, skip: [:sessions]
devise_scope :user do
get '/login' => 'users/sessions#new', as: :new_user_session
post '/login' => 'users/sessions#create', as: :user_session
get '/logout' => 'users/sessions#destroy', as: :destroy_user_session
end
authenticated do
devise_scope :user do
root to: 'application#index', as: 'authenticated_user_root'
end
end
unauthenticated do
devise_scope :user do
root to: redirect('/login'), as: "unauthenticated_user"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment