Skip to content

Instantly share code, notes, and snippets.

@rlmattax
Created October 27, 2012 04:20
Show Gist options
  • Save rlmattax/3962926 to your computer and use it in GitHub Desktop.
Save rlmattax/3962926 to your computer and use it in GitHub Desktop.
Active Admin User Impersonation
ActiveAdmin.register User do
menu :parent => "Users"
member_action :impersonate, :method => :get do
user = User.find(params[:id])
flash[:notice] = "Successfully logged in as : #{user.email} #{view_context.link_to('Be careful!', root_path)}".html_safe
begin
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 :only => :show do
link_to('Impersonate', impersonate_admin_user_path(resource))
end
index do
column :id
column :email
column :created_at
column :current_sign_in_at
column :last_sign_in_at
column :completed_wizard
column "Special" do |resource|
link_to("Impersonate", impersonate_admin_user_path(resource), :class => "member_link edit_link")
end
default_actions
end
form do |f|
f.inputs "User Details" do
f.input :email
end
f.buttons
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment