我正在使用Devise,密码更改是重定向到主页,如何保持/ users / edit?
我正在使用/devise/registrations/edit.html.erb
,视图文件是/devise/registrations/edit.html.erb
(我没有对它进行任何更改):
"off" %> (we need your current password to confirm your changes)
当用户更改密码时,他们将被重定向到root_url
(主页)。 我想将它们保存在更改密码页面,即/users/edit
。 我该怎么做?
编辑 – 我有编辑方法的registration_controller,我应该添加什么?
首先,OP在更改密码后有重定向问题,在设计中更改密码在RegistrationsController
,而PasswordsController
用于“重置密码”。 FYI @ amesee重置密码后重定向的答案。 更改密码和重置密码是不同的
操作方法:在用户编辑其配置文件后自定义重定向,并查看after_update_path_for(资源)
您应该在after_update_path_for(resource)
上添加after_update_path_for(resource)
方法,如下所示:
class RegistrationsController < Devise::RegistrationsController protected def after_update_path_for(resource) root_path end end
PasswordsController
的update
操作调用名为after_resetting_password_path_for
的受保护方法。
该方法只调用after_sign_in_path_for
所以我认为将after_sign_in_path_for
子类化并覆盖此方法应该是安全的。
看起来已经有一个测试,因为这个方法被覆盖,所以看起来它肯定是支持的。
如果您有用户和管理员的不同型号,您需要:
的routes.rb
devise_for :admins, controllers: {registrations: 'admins/registrations'}, defaults: { format: 'html' }
应用程序/控制器/管理员/ registration_controller.rb
class Admins::RegistrationsController < Devise::RegistrationsController def after_update_path_for(resource) after_change_password_path # change this end end