1
votes

I know how to change the password using devise but I don't know how to create a link to an action for the current admin user. For example adding a link under the email.

Change password

and that would send to an action calling:

send_reset_password_instructions

I can't really find any good documentation for ActiveAdmin, the official site expose some examples but nothing there is really explained. Its unclear where and how things works.

1

1 Answers

5
votes

You'll want to look at ActiveAdmin's documentation on custom controller actions. I've accomplished this by creating a "member_action" (a custom controller action which acts upon a single record), and adding an "action_item" to perform it (those are the buttons which appear in the top right when viewing a record). Here's how I make it work:

# in app/admin/admin_users.rb
action_item do
  # Link to perform the member_action, "reset_password" defined below
  link_to("Reset Password", reset_password_admin_admin_user_path(admin_user))
end

member_action :reset_password do
  # Find the user in question
  admin_user = AdminUser.find(params[:id])

  # Call the method (from Devise) which sends them a password reset email
  admin_user.send_reset_password_instructions

  # Redirect back to the user's page with a confirmation
  redirect_to(admin_admin_user_path(admin_user),
    notice: "Password reset email sent to #{admin_user.email}")
end