Allow admin to impersonate all other users

Hi everyone!

I’m working on a function that allows any admin to mimic or impersonate other users. In other words, I want the admin to be able to freely access any user’s personal dashboard. I came across a gem by Engine Yard called User_Impersonate (GitHub - engineyard/user_impersonate: Allow your support staff to impersonate users to see what they see). It looks promising, but is fairly new so I was interested in other alternatives to accomplish this.

I’m also using Devise. As an alternative to the above gem, could I just reconfig the Devise route so that the edit user page is no longer user/edit but something like users/:user_id/edit. If you had to implement something similar, how did you handle it? Thanks!

1 Like

Hi @realDLee, if I was using Devise and wanted to do that functionality I would definitely look at using the user_impersonate gem, it’s 11 months old and looks like it’s actively maintained, so I wouldn’t consider it that new.

If you really only want admin’s to be able to edit users, and do other admin functionality, not actually impersonate users and see what they see on the site, then I think you should consider implementing an actual admin interface. Either by hand or using something like GitHub - railsadminteam/rails_admin: RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data

Let me know what you think, if you have any follow up questions, and also what you end up doing!

thanks,
-Chad

Here’s another gem that does impersonation: GitHub - ankane/pretender: Log in as another user in Rails

Anybody try it?

Here’s the gem that @cpytel is referring to: GitHub - userimpersonate/user_impersonate2: Allow your support staff to impersonate users to see what they see.

It ROCKS! super easy to install, and gets the job done.

1 Like

Thanks for the recommendation @cpytel and @Justin_Gordon!

I was about to implement this type of feature for my admin users with the method outlined in the Devise wiki here: How To: Sign in as another user if you are an admin · heartcombo/devise Wiki · GitHub

This is a really simple version and once an admin has become another user they would be required to sign out and sign back in again as admin to regain control.

The gem mentioned above looks much better and will give my admin users a much slicker experience.

It looks like there are a number of workable solutions already mentioned on the thread but I’ll throw one more out that is more manual, in tutorial form: How To Masquerade As Another User To See How They Use Your App

1 Like

This is awesome! I’ve been always hacking to impersonate some users and never occured to me to search for a solution like this. The gem user_impersonate2 worked like a charm with devise.

There’s just one issue with me, I have 2 different user models: candidate and recruiter. Wondering if/how I could use this gem for those 2 models. Because from what I saw, it’s only possible to use for one user model.