4

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

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')

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?

Ernesto G
  • 525
  • 6
  • 20

2 Answers2

4

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
Administrate 0.12.0

Sujeev
  • 276
  • 4
  • 10
  • This works fine for adding a new user, but if you ever need to edit them, then you need to set the password for them. That's fine in dev mode when you are creating your own users and can set the passwords, but isn't so good on production when you might need to update real users whose passwords you don't know. – charlesdeb Jul 01 '23 at 22:06
0

You can use devise_invitable

And then you have a form to invite user by Email, and the user enter his password (is not safe that you set the user password)

inye
  • 1,786
  • 1
  • 23
  • 31
  • I really need to set the password for my users. Our client doesn't want to use emai adresses to register users, so eventually will have to switch to a :name attribute to use as ID. These users won't be associated with persons as well (apart from the admin user), they will be generic users created for each department, – Ernesto G Jan 16 '18 at 12:32