I am using devise and the views file is /devise/registrations/edit.html.erb
(I have not made any changes to it):
<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>
When the user changes their password, they are getting redirected to root_url
(homepage). I want to keep them at the change password page, which is /users/edit
. How can I do it?
EDIT - I do have registration_controller with edit method, what should I add in it ?
The update
action in PasswordsController
calls a protected method named after_resetting_password_path_for
.
The method just calls after_sign_in_path_for
so I think it should be safe to subclass PasswordsController
and override this method.
It looks like there's is already a test for whent this method is overridden so it looks like it's definitely supported.
First, OP have problem about redirect after change password, change password in devise is in the RegistrationsController
, while PasswordsController
for "Reset Password". FYI @amesee's answer for redirect after reset password. Change password and reset password are differents
How To: Customize the redirect after a user edits their profile and see after_update_path_for(resource)
You should add after_update_path_for(resource)
method on your registrations_controller.rb
looks like :
class RegistrationsController < Devise::RegistrationsController
protected
def after_update_path_for(resource)
root_path
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With