【问题标题】:ActiveAdmin change password inside appActiveAdmin 在应用程序内更改密码
【发布时间】:2015-04-10 02:06:08
【问题描述】:

我关闭了Devise Page,以便用户可以在 ActiveAdmin 中更改他们的密码。方法 3 不能按原样工作,所以我不得不为 ActiveAdmin 稍微修改一下

ActiveAdmin.register_page 'UserPassword' do

  def user_params
    params.required(:user).permit(:password, :password_confirmation)
  end

  page_action :update_password, method: :post do
    @user = AdminUser.find(current_admin_user.id)
    if @user.update(params.required(:user).permit(:password, :password_confirmation))
      # Sign in the user by passing validation in case their password changed
      sign_in @user, :bypass => true
      redirect_to admin_root_path, notice: "Your password was changed"
    else
      redirect_to admin_userpassword_path, alert: "Your password couldn't be changed"

    end
  end

  content do
    render partial: 'edit', locals: {user: current_admin_user}
  end
end

我不得不更改if @user.update(params.required(:user).permit(:password, :password_confirmation)),因为if (@user.update(user_params)) 会抛出一个错误说undefined local variable or method user_params

我在上面列出的代码是允许用户在 ActiveAdmin 布局中更改密码的正确方法吗?

【问题讨论】:

    标签: ruby-on-rails-4 devise activeadmin


    【解决方案1】:

    我会将用户模型注册为 ActiveAdmin 中的资源。然后你可以使用表单块创建一个表单,用户可以在其中更改密码。

    ActiveAdmin.register User do
      ...
      form do |f|
        inputs 'Details' do
          input :password
          input :password_confirmation
        end
        actions
      end
      ...
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 2020-01-25
      • 2013-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多