ruby-on-railsdeviserails-administrateadministrate

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: '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?


Solution

  • 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