Implementing a "sudo" feature when using devise

I’m considering implementing a “sudo” type feature where an admin can login and see the app just as a specific user sees it, in order to help diagnose customer issues.

Has anybody else ever done this? Any advice? Right now, “current_user” is used extensively throughout views and controllers, so maybe the right place to fix this would be to override the devise method in some way. A cleaner option might be to search and replace my code with a controller helper called “active_user” and have that access the current_user and return the right user, being the current_user or else a given user if the current_user is an admin and doing a “sudo”. The problem with this approach is that my app has over 200 references to current_user.

Any advice on such a feature? Any easier way to do it? Would this functionality be a potentially useful as gem?

Take a look at our blog post How To Masquerade As Another User….