如何通过直接从 Active Admin 中的 edit_page 设计身份验证令牌来重置用户密码?

How to reset user´s password by Devise authentication token directly from edit_page in Active Admin?

我希望 admin_user 能够从 Active Admin edit_page 重置用户密码,但目前卡住了。

我的想法是制作一个 action_item 按钮并从设计身份验证 gem 中为有效的用户对象启动 @user.send_reset_password_instructions 方法。但是,action_item 无法收到任何通知:消息,这就是我卡住的地方。

你能帮我实现 action_item 按钮,它可以启动 @user.send_reset_password_instructions,重定向到同一个用户_edit_page 并且 flash 通知消息发送成功而不渲染任何其他视图??

action_item :reset_password,only: :edit do
  link_to "Reset password",edit_timein_employee_path
end

controller do
   def reset_password
    super do |success,failure|
    employee.send_reset_password_instructions
  end
 end
end

非常感谢!!

我会这样做:确保将其粘贴到 app/admin/admin_user.rb 文件中。我不会直接添加控制器方法,但会使用 member_action dsl 指令来添加逻辑。祝你好运!

action_item :reset_password, :only => :edit do
 link_to 'Reset password',  do_password_reset_admin_admin_user_path(resource), :method => :post
end

member_action :do_password_reset, :method => :post do
  flash.notice = "A mail containing password reset instructions has been sent to: #{resource.email}"
  resource.send_reset_password_instructions
  redirect_to edit_admin_admin_user_path(resource) and return
end