How to override PasswordsController actions in rails application with ActiveAdmin & Devise

I have a rails application that is configured to use ActiveAdmin and Devise.

I want to override editing and updating actions in PasswordsController. As far as I can tell, ActiveAdmin relies on the Devise PasswordsController.

Do I need to use the ActiveAdmin method to configure the controller / resource for this? If so, what resource is in the game to “register” for PasswordsController?

Or do I need to copy the Devise all PasswordsController from a gem to a place somewhere in my application and change the actions I want to change? If so, in which folder would I put my copy of the Devise controller to override the gem version?

What is the right way to do this?

+4
source share
1 answer

All development-related code is in lib/active_admin/devise.rb, including these controller definitions:

module ActiveAdmin
  module Devise

    class SessionsController < ::Devise::SessionsController
      include ::ActiveAdmin::Devise::Controller
    end

    class PasswordsController < ::Devise::PasswordsController
      include ::ActiveAdmin::Devise::Controller
    end

    class UnlocksController < ::Devise::UnlocksController
      include ::ActiveAdmin::Devise::Controller
    end

    class RegistrationsController < ::Devise::RegistrationsController
       include ::ActiveAdmin::Devise::Controller
    end

    class ConfirmationsController < ::Devise::ConfirmationsController
       include ::ActiveAdmin::Devise::Controller
    end

  end
end

You should have the ability to render harmless PasswordsControllerin order to change its behavior inside your application:

# config/initializers/active_admin_devise_sessions_controller.rb
class ActiveAdmin::Devise::PasswordsController

  # ...

end
+4
source

Source: https://habr.com/ru/post/1526436/


All Articles