Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Admin - Become Another User

I'm using Rails 3.0.10 and I'm currently using CanCan for determining the different abilities that users have within the application.

I am using Devise for the user authentication itself.

Is there a good way for an admin user to "become" another user temporarily using CanCan? This would be especially useful to become specific users who may be experiencing unique issues pertaining to their account.

So in simple terms, I just want to be able to sign in as any given user to see what they see. Not sure if there is a CanCan or Devise feature out there.

UPDATE

I just came across this:

How-To: Sign in as another user if you are an Admin.

I haven't tested it yet, but it may be the answer I was looking for!! Feel free to provide some insight if this is the approach you took, or if you have another idea!

like image 909
ardavis Avatar asked Aug 16 '26 02:08

ardavis


1 Answers

I found what I was looking for, and there's a gem for it!

switch_user

It was really easy to use. I just have to add gem switch_user to my Gemfile.

Then add <%= switch_user_select %> to my layout. Exactly what I wanted!

like image 73
ardavis Avatar answered Aug 18 '26 17:08

ardavis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!