Context

  • The idea is to develop the same requirement as devise describe in their guide:

  • The project is using the admin_user approach and sets the default setup included on activeadmin.

  • (NOTE) One other recommended solution is to migrate the admin_user model to user and configure devise normally as a separate engine.

Guide

  • If you haven’t already, enable the confirmable module

  • If you haven’t already, follow the Devise instructions for configuring views, install in app/views/active_admin/devise

  • Remove the password and password_confirmation inputs from your views/active_admin/devise/registrations/new.html.erb

  • Override the Devise definition of password_required? in your model admin_user:

    protected
    
    def password_required?
      confirmed? ? super : false
    end
    
  • Tweak the language in views/active_admin/devise/passwords/edit.html.erb by changing:

    • the page title from “Change your password” to “Set your password”
    • the submit button value from “Change my password” to “Set my password”
  • Override the Devise definition of after_confirmation_path_for in your ConfirmationsController:

    To work correctly you must need to create a monkey patching as described below:

    # config/initializers/active_admin_devise_confirmations_controller.rb
    class ActiveAdmin::Devise::ConfirmationsController
      def after_confirmation_path_for(_resource_name, resource)
        token = resource.send(:set_reset_password_token)
        edit_password_url(resource, reset_password_token: token)
      end
    end
    
  • To edit the mail views you need to move the generated views from app/views/active_admin/devise/mailer to app/views/devise/mailer and edit them.

  • Add a test in your model to catch any changes in Devise’s behavior in the future (because set_reset_password_token is a protected method):

    describe '#set_reset_password_token' do
      it 'returns the plaintext token' do
        potential_token = subject.send(:set_reset_password_token)
        potential_token_digest =
          Devise.token_generator.digest(subject, :reset_password_token, potential_token)
        actual_token_digest = subject.reset_password_token
        expect(potential_token_digest).to eql(actual_token_digest)
      end
    end
    

Conclusions

The solution provides here is not recommended to use, only follow this guide if you don’t mind moving from hacky activeadmin-devise default installation to a separate devise installation by lack of time, experience or the migration is nonsense at this moment.