Last Updated: February 25, 2016
·
1.047K
· danielpclark

Create an ActiveAdmin account by Cloning a Devise User account

Need to create an admin account for ActiveAdmin but don't want to go through account creation and password re-entry twice? Use this method to get the job done.

def new_admin_user_from_devise(user_id)
  user = User.find(user_id)

  unwanted = ["id", "sign_in_count", "created_at", "updated_at", "current_sign_in_at", "last_sign_in_at", "current_sign_in_ip", "last_sign_in_ip"]

  AdminUser.new(
    AdminUser.column_names.map {|i|
      { i => user[i] }
    }.inject(:update).except(unwanted)
  ).save(validate: false)

end

This copies your already encrypted password account over. Works great!