Created
October 27, 2012 04:20
-
-
Save rlmattax/3962926 to your computer and use it in GitHub Desktop.
Active Admin User Impersonation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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