Adding New Admins to Active Admin

35,489

Solution 1

What brian said works perfectly http://net.tutsplus.com/tutorials/ruby/create-beautiful-administration-interfaces-with-active-admin/

AdminUser.create!(:email => '[email protected]', :password => 'password', :password_confirmation => 'password')

Solution 2

What Brian said works, but if you want to set the password in the interface rather than have it send a reset email try this:

Leave the admin_user model at its original generated default, then in app/admin/admin_users.rb:

ActiveAdmin.register AdminUser do
  index do
    column :email
    column :current_sign_in_at
    column :last_sign_in_at
    column :sign_in_count
    default_actions
  end

  form do |f|
    f.inputs "Admin Details" do
      f.input :email
      f.input :password
      f.input :password_confirmation
    end
    f.buttons
  end
end

Solution 3

  1. login: [email protected] password: password => login
  2. go to http://localhost:3000/admin/admin_users

If you want create users (devise users, table "users") in admin panel:

  1. $ rails generate active_admin:resource user
  2. app/admin/user.rb:

ActiveAdmin.register User do
  permit_params :email, :name, :password, :password_confirmation

  index do
    column :name
    column :email
    actions
  end

  form do |f|
    f.inputs 'User' do
      f.input :name
      f.input :email
      f.input :password
      f.input :password_confirmation
    end
    f.actions
  end
end

Solution 4

this is the new syntax AdminUser.create!(email: "[email protected]", password: "password123", password_confirmation: "password123")

Share:
35,489

Related videos on Youtube

alik
Author by

alik

Updated on April 20, 2020

Comments

  • alik
    alik about 4 years

    I am using devise for my users. I recently installed the rails Active Admin gem, everything is working beautifully.

    However I can't figure out how to add a new admin users. I can see that active admin created an admin_user table in the db with a user [email protected], which I use to log in to the interface.

    I tried adding admin_user as a resource so that I can just click the Add Admin User button within the active admin interface to add a new user, however that does not seem to work.

    • Brian
      Brian over 12 years
      Check out step 2 of this tutorial, it may help: net.tutsplus.com/tutorials/ruby/…
    • Brian
      Brian over 12 years
      additional fyi: this is the code Active Admin uses to create the default admin user: AdminUser.create!(:email => '[email protected]', :password => 'password', :password_confirmation => 'password')
  • Admin
    Admin over 12 years
    I cannot get this to send an email...any ideas?
  • Scott
    Scott over 12 years
    did you see brian's 2nd comment?
  • Scott
    Scott over 12 years
  • jpw
    jpw over 12 years
    I found emails went out after I re-started my localhost server after changing the active admin files per the tutorial (should have know to do it, but forgot)
  • Nubtacular
    Nubtacular over 11 years
    Thanks for posting this here @Nate914375. Very helpful and didn't have to do much searching around :)
  • Patrick
    Patrick about 9 years
    For those new to Rails, first run the rails console, $ rails c, then execute the above statement in the console, # AdminUser.create!(...)