ruby-on-rails – 我正在使用Devise,密码更改是重定向到主页,如何保持/ users / edit?

我正在使用devise,视图文件是/devise/registrations/edit.html.erb(我没有对它进行任何更改):
<div><%= f.label :password %>
<%= f.password_field :password,:autocomplete => "off" %></div>

<div><%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %></div>

<% if f.object.encrypted_password.present? %>
   <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
   <%= f.password_field :current_password %></div>
<% end %>
<div><%= f.submit "Update" %></div>

用户更改密码时,他们将被重定向到root_url(主页).我想将它们保存在更改密码页面,即/ users / edit.我该怎么做?

编辑 – 我有编辑方法的registration_controller,我应该添加什么?

解决方法

首先,OP在更改密码后有重定向问题,在设计中更改密码在RegistrationsController中,而PasswordsController用于“重置密码”. FYI @ amesee重置密码重定向的答案.更改密码和重置密码是不同的

How To: Customize the redirect after a user edits their profile并见after_update_path_for(resource)

您应该在registrations_controller.rb上添加after_update_path_for(resource)方法,如下所示:

class RegistrationsController < Devise::RegistrationsController

  protected

    def after_update_path_for(resource)
      root_path
    end
end

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...