Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am using Devise, the password change is redirecting to home page, how to keep it on /users/edit?

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 ?

like image 679
iCyborg Avatar asked Jul 23 '13 16:07

iCyborg


2 Answers

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.

like image 154
James Avatar answered Oct 21 '22 07:10

James


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
like image 21
rails_id Avatar answered Oct 21 '22 07:10

rails_id