You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 25, 2021. It is now read-only.
Repository navigation
How To: Sign in as another user if you are an admin
leereilly edited this page Jan 16, 2012
·
4 revisions
This is a useful administration feature I've seen on a few apps where you can quickly "become" one of the users to see what their profile and screens look like.
The implementation is simple but it took me a while to find out how to do it, so I'm recording it here:
classAdminController < ApplicationControllerbefore_filterauthenticate_user!defbecomereturnunlesscurrent_user.is_an_admin?sign_in(:user,User.find(params[:id]))redirect_toroot_url# or user_root_urlendend
If you want to ensure that last_sign_in_at and current_sign_in aren't updated when becoming the user, you can replace sign_in(:user, User.find(params[:id])) with sign_in User.find(params[:id]), :bypass => true in the example above. The :bypass option bypasses warden callbacks and stores the user straight in the session.
For a slightly more advanced & customizable implementation of this concept, packaged as a gem, check out flyerhzm's switch_user project.