【发布时间】:2015-05-07 15:12:33
【问题描述】:
我在 Rails 4.2.1 并设计 3.4.1。我基本上同时想要两件事:
Allow users to edit their password
和
Allow users to edit their account without providing a password
我设法让他们分开工作。但是第一个问题的解决方案 1 恐怕与第二个问题的唯一官方解决方案不兼容,因为对于后者,我需要覆盖 registration em>控制器。
因此我尝试在 registration 控制器而不是 application 控制器中执行 solution 1 工作:
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :configure_account_update_params, only: [:update]
protected
def configure_account_update_params
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name, :password, :password_confirmation, :current_password) }
end
def update_resource(resource, params)
resource.update_without_password(params)
end
end
这种方式只有像 name 这样添加的属性会在密码被完全过滤掉的情况下得到更新。 我不确定我是否应该像 解决方案 2 和 3 中那样为这样一个简单的目标开始大量定制。我错过了什么吗?
【问题讨论】:
标签: ruby-on-rails devise