问题
I would like the admin_user to be able to reset user´s password from Active Admin edit_page, but am currently stuck.
My idea was to make an action_item button and launch @user.send_reset_password_instructions method from devise authentication gem for a users object which works. But, action_item cannot get any notice: message and that´s where I´m stuck.
Can you please help me implement the action_item button which could launch the @user.send_reset_password_instructions, redirect to the same user_edit_page and flash notice message sending successful without rendering any other view??
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
Thanks a lot!!
回答1:
I would do it this way: make sure to paste this in the app/admin/admin_user.rb
file. I would not add controller methods directly but would use the member_action
dsl directive to add logic. Good luck!
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
来源:https://stackoverflow.com/questions/54470272/how-to-reset-user%c2%b4s-password-by-devise-authentication-token-directly-from-edit-p