Ruby-on-rails 将新管理员添加到活动管理员
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7590609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding New Admins to Active Admin
提问by alik
I am using devise for my users. I recently installed the rails Active Admin gem, everything is working beautifully.
我正在为我的用户使用设计。我最近安装了 rails Active Admin gem,一切正常。
However I can't figure out how to add a new admin users. I can see that active admin created an admin_usertable in the db with a user [email protected], which I use to log in to the interface.
但是我不知道如何添加新的管理员用户。我可以看到活动管理员admin_user使用用户 [email protected] 在数据库中创建了一个表,我用它来登录界面。
I tried adding admin_useras 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.
我尝试添加admin_user为资源,以便我只需单击活动管理界面中的“添加管理员用户”按钮即可添加新用户,但这似乎不起作用。
回答by Scott
What brian said works perfectly http://net.tutsplus.com/tutorials/ruby/create-beautiful-administration-interfaces-with-active-admin/
布赖恩所说的工作完美 http://net.tutsplus.com/tutorials/ruby/create-beautiful-administration-interfaces-with-active-admin/
AdminUser.create!(:email => '[email protected]', :password => 'password', :password_confirmation => 'password')
回答by Nate914375
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:
将 admin_user 模型保留为其原始生成的默认值,然后在 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
回答by Oleksandr Melnyk
- login: [email protected] password: password => login
- go to http://localhost:3000/admin/admin_users
- 登录:[email protected] 密码:密码 => 登录
- 转到http://localhost:3000/admin/admin_users
If you want create users (devise users, table "users") in admin panel:
如果您想在管理面板中创建用户(设计用户,表“用户”):
- $ rails generate active_admin:resource user
- app/admin/user.rb:
- $ rails 生成 active_admin:resource 用户
- 应用程序/管理员/用户.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
回答by gsumk
this is the new syntax
AdminUser.create!(email: "[email protected]", password: "password123", password_confirmation: "password123")
这是新语法
AdminUser.create!(email: "[email protected]", password: "password123", password_confirmation: "password123")

