I am trying to implement a reset password page using Devise.
What I want to achieve is to redirect the page to a different route after the password is being updated. So, I made the change in my passwords_controller.rb
based on the documentation.
My Controller looks like this:
class Users::PasswordsController < Devise::PasswordsController
# basic is my html.erb file for layout purpose....
layout "basic"
def edit
render :edit
end
def after_resetting_password_path_for(resource)
root_path
end
end
In my routes.rb
file. I have included the route for password controller:
devise_for :users, :controllers => {
:sessions => "users/sessions",
:passwords => "users/passwords",
}
Here, I am able to access my view in app/views/passwords/edit.html.erb
.
The problem is the after_resseting_password_path_for
method (which is being overridden in passwords_controller.rb
) which is not getting executed and I am redirected to the same page in my output instead of root_path
. Also the update is not made.
Is it the problem with the update method implemented in Devise or I am missing something?
I suspect that – since you've overridden the default Devise
PasswordsController
– youredit
action is looking to post to anupdate
action in the same controller, but there is none. Try updating your custom controller to the following:Alternatively, I imagine that if you were to specify
after_resetting_passwords_path
in yourApplicationController
, you'd be able to bypass overridingDevise::PasswordsController
entirely (though you'd need to conditionally set your layout in theApplicationController
).