Ernesto G
Ernesto G

Reputation: 545

Rails. Create Devise users directly from Administrate panel

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: '[email protected]', 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?

Upvotes: 4

Views: 1111

Answers (2)

Sujeev
Sujeev

Reputation: 306

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

Upvotes: 4

inye
inye

Reputation: 1796

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)

Upvotes: 0

Related Questions