문제

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

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top