You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails ActiveAdmin:自定义密码重置动作跳转至自定义视图

Fixing the ActiveAdmin Password Reset Custom Action

Hey there! Let's get your password reset action working smoothly with the custom view and ActiveAdmin's default layout. Here's the corrected code and a breakdown of what was adjusted:

Corrected Full Code

ActiveAdmin.register User do
  # Register the custom route and define the action logic
  member_action :password_reset, method: :get do
    @user = User.find(params[:id])
    # This will automatically render your custom view at app/views/active_admin/users/password_reset.html.erb
  end

  # Add the "Password reset" button to the user edit page
  action_item only: :edit do
    link_to "Password reset", admin_user_password_reset_path(resource)
  end
end

Key Fixes & Explanations

  • Swapped action_view for action_item: action_item is the proper ActiveAdmin method to add custom action buttons to resource pages. We use only: :edit to ensure the button only shows up on the user edit page.
  • Added member_action: This registers the custom route for your password reset action (ActiveAuto generates the named route admin_user_password_reset_path automatically). We set method: :get since we're just loading a view page.
  • Fixed params[id] to params[:id]: Ruby hash keys require colons for symbols—this was a syntax error that would have broken user lookup.
  • Used resource in the link: resource is an ActiveAdmin helper that refers to the current user being edited, so we don't need to manually pass user.id (though admin_user_password_reset_path(user) would also work).

Making the Custom View Work

Double-check your view file is saved at app/views/active_admin/users/password_reset.html.erb. Since the controller inherits from ActiveAdmin::BaseController, it will automatically use ActiveAdmin's default layout for this view—no extra setup needed! You can add your password reset form or instructions directly in this ERB file.

内容的提问来源于stack exchange,提问作者Karthik Muthu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:07:07