加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 我正在使用Devise,密码更改是重定向到主页,如

发布时间:2020-12-17 04:35:44 所属栏目:百科 来源:网络整理
导读:我正在使用devise,视图文件是/devise/registrations/edit.html.erb(我没有对它进行任何更改): div%= f.label :password %%= f.password_field :password,:autocomplete = "off" %/divdiv%= f.label :password_confirmation %%= f.password_field :password_
我正在使用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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读