Skip to content

Instantly share code, notes, and snippets.

@nativestranger
Last active November 3, 2016 21:47
Show Gist options
  • Save nativestranger/af3ff70d1cd03ea9376aed34c79a168e to your computer and use it in GitHub Desktop.
Save nativestranger/af3ff70d1cd03ea9376aed34c79a168e to your computer and use it in GitHub Desktop.
# within app/admin/users.rb
member_action :impersonate, :method => :get do
user = User.find(params[:id])
begin
flash[:notice] = "Successfully logged in as : #{user.email} #{view_context.link_to('Be careful!', root_path)}".html_safe
warden.set_user(resource,{:scope=>:user,:run_callbacks=>false})
rescue
flash[:error] = "Unable to log you in. Poop."
end
redirect_to admin_users_path
end
action_item(:impersonate, only: :show) do
link_to('Impersonate', impersonate_admin_user_path(resource))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment