滑轨。直接从“管理”面板创建Devise用户 [英] Rails. Create Devise users directly from Administrate panel

查看:46
本文介绍了滑轨。直接从“管理”面板创建Devise用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用devise直接从控制台创建用户,因此不使用:registerable 模块。

I'm using devise to create users directly from console, in consequence not using the :registerable module.

从控制台创建用户的方法是通过以下方式提供电子邮件,密码和password_conformation:

The way to create users from the console is by providing email, password and password_conformation this way:

User.create(email: 'john@hotmail.com', password: '1234', password_conformation: '1234')

现在,我已经安装了Administrate gem,并且希望能够直接从那里创建用户。我已经可以编辑自定义字段并销毁用户,但是我不知道如何创建它们,因为password或password_confirmation都不属于User表。有什么想法吗?

Now I have installed the Administrate gem and I would like to be able to create users directly from there. I already can edit custom fields and destroy users, but I don't know how to create them since neither password or password_confirmation belongs to the User table. Any Thoughts?

推荐答案

我添加了密码 password_confirmation 字段添加到仪表板,它像一个魅力一样工作,下面我提供了包含相关字段的仪表板示例。

I added the password and password_confirmation fields to the dashboard and it worked like a charm, following I have included a sample of the dashboard with the relevant fields.

require "administrate/base_dashboard"

class AdminUserDashboard < Administrate::BaseDashboard

  ATTRIBUTE_TYPES = {
    .
    .
    .
    password: Field::String,
    password_confirmation: Field::String,
    .
    .
    .
  }.freeze

  # FORM_ATTRIBUTES
  FORM_ATTRIBUTES = %i[
  .
  .
  .
  password
  password_confirmation
  .
  .
  .
  ].freeze

end



我在以下位置对此进行了测试:


I tested this on:

Rails 6

Devise 4.7.1

管理0.12.0

Rails 6
Devise 4.7.1
Administrate 0.12.0

这篇关于滑轨。直接从“管理”面板创建Devise用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆