How To: Using ActiveAdmin to login as any user

ConfusedVorlon edited this page Aug 28, 2017 · 3 revisions
Clone this wiki locally

As a way to provide support to end users, the ability to login to their rails app as a specific user can be useful. If you're using ActiveAdmin and Devise, adding this feature takes less than 10 minutes.

The feature consisted of two changes, customising the ActiveAdmin User show page and adding a custom member action that logs in the user.

Code Snippet 1-a: show page

show do |user|
    attributes_table do
      #We want to keep the existing columns
      User.column_names.each do |column|
        row column
      #This is where we add a new column
      row :login_as do
        link_to "#{}", login_as_admin_user_path(user), :target => '_blank'

Next we'll add the login_as member action to ActiveAdmin (

Code Snippet 1-b: member action

  # Allows admins to login as a user 
  member_action :login_as, :method => :get do
    user = User.find(params[:id])
    redirect_to account_path 

....And there you have it. Now admin users can quickly log in as any user for quick trouble shooting, user testing, etc.

Taken from on 27th July 2013.