Devise Master Account
-
25-10-2019 - |
Question
I am making a website for me and my friends to organise games online. I am using Rails 3 and Devise. I was basically wanting to be able to login to the accounts of other users without needing a password to do this. I looked at using a authorization gem list CanCan but this is not really what I am looking for.
It would be in a sense session switching. Has anyone done this before with Devise? If I have not explained it well please let me know.
R
Solution
Create an action that does this:
class AdminController < ApplicationController
before_filter authenticate_user!
def become
return unless current_user.is_an_admin?
sign_in(:user, User.find(params[:id]))
redirect_to root_url # or user_root_url
end
end
More info on Devise's wiki entry about it https://github.com/plataformatec/devise/wiki/How-To:-Sign-in-as-another-user-if-you-are-an-admin
OTHER TIPS
You really do want something like CanCan for this, I think. Why do you think you don't?
Regardless, you're going to want to store roles for your users.