简体   繁体   中英

rails devise edit_user_password_path

I cannot route to the edit_user_password_path on my project. It just routes to home. Can someone please assist?

<%= link_to "Change Password", edit_user_password_path(current_user) %>

The answer to this question explains the issue: Showing the devise edit password screen

In brief, the PasswordsController is used for password resetting when a user is not signed in. If you're signed in, it redirects you to the root path.

In order to edit the password, you want to use the RegistrationsController instead.

I faced the same issue

new_user_password_path and edit_user_password_path, both redirects to the root page. If you are signed in, it will redirect to root page and if user is not signed in, it will ask for sign in and then it redirects to root page.

For this you need to use edit_user_registration_path of devise RegistrationController.

Result of my rake routes is

user_password POST /users/password(.:format){:action=>"create", :controller=>"devise/passwords"}

new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}

edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}

PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}

Show us your entire routes.rb , it's possible that you have a rule in there that routes edge cases to home. I've seen it before.

I think DEVISE gem reroutes to root everytime it fails to find smthing

devise_for :users resources :users

root :to => "pubpages#homepage"

Devise::PasswordsController#edit is for non-authenticated users so it will definitely move to the root path which is after the sign_in path because you are already sign_in. So you have to use Devise::RegistrationsController#edit to changing your password but you can open this link in incognito mode or your can try to remove your browser cookies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM