简体   繁体   中英

How to immitate Devise's sign_in(@user) helper method?

I tried in do it like this in application_controller.rb

helper_method: sign_in

def sign_in(email, password)
        valid_params = { email: email, password: password }
        post login_path, params: valid_params
end

is this a best way?

Something that I like to do is

class Admins::UsersController < AdminController
  ...
  def login_as
    sign_in(User.find(params[:user_id]), :bypass => true)
    redirect_to users_root_path
  end
end

you should not pass a user_id but some sort of key or a uuid but you get the gist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM