Skip to content

Instantly share code, notes, and snippets.

@LolWalid
Last active October 4, 2016 21:36
Show Gist options
  • Select an option

  • Save LolWalid/b651297fbf5b826ef15e40b814b26656 to your computer and use it in GitHub Desktop.

Select an option

Save LolWalid/b651297fbf5b826ef15e40b814b26656 to your computer and use it in GitHub Desktop.
Mutiple model devise
# app/controllers/admin
class Admin::PostController < ActionController::Base
before_action :authenticate_admin!
def index
@posts = Post.all
end
def switch_user
if admin_signed_in?
sign_out(:admin)
sign_in(:partner, User.first)
end
redirect_to api_api_index_path
end
def authenticate_admin!
sign_out(:user) if user_signed_in?
super
end
end
# routes.rb
Rails.application.routes.draw do
namespace :admin do
resources :posts do
post :switch_user, on: :collection
end
end
devise_for :admins, path: 'admin', skip: :registrations
devise_for :users
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment