我正在使用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.我该怎么做?
解决方法
首先,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