2012-06-21 2 views
1

devise를 사용하여 비밀번호를 변경하는 방법을 알고 있지만 현재 관리 사용자에 대한 작업 링크를 만드는 방법을 모르겠습니다. 예를 들어 이메일 아래에 링크를 추가합니다.activeadmin 비밀번호 변경 버튼

암호 변경

하고는 액션 호출에 보낼 것이다 :

send_reset_password_instructions 

난 정말, 공식 사이트가 몇 가지 예를 노출 ActiveAdmin을위한 좋은 문서를 찾을 수 없습니다 아무것도하지만 정말이 설명되지 않는다 . 그것의 명확하지 않은 것들이 어떻게 작동하는지.

답변

3

ActiveAdmin의 documentation on custom controller actions을 살펴 보겠습니다. 나는 이것을 달성하기 위해 "member_action"(하나의 레코드에 대해 작동하는 커스텀 컨트롤러 액션)을 만들고 "action_item"을 추가하여 레코드를 볼 때 오른쪽 상단에 나타나는 버튼입니다. 다음은 작동 방식입니다.

# 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