Last active
October 4, 2016 21:36
-
-
Save LolWalid/b651297fbf5b826ef15e40b814b26656 to your computer and use it in GitHub Desktop.
Mutiple model devise
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
| # 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