Adding New Admins to Active Admin

狂风中的少年 提交于 2019-12-20 08:27:26

问题


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 admin@example.com, 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.


回答1:


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

AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')



回答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



回答3:


  1. login: admin@example.com 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



回答4:


this is the new syntax AdminUser.create!(email: "youremail@domain.com", password: "password123", password_confirmation: "password123")



来源:https://stackoverflow.com/questions/7590609/adding-new-admins-to-active-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!