[英]Rails Devise password edit not working
我在菜单中有以下链接:
<li><%= link_to "Change your password", edit_user_registration_path %>
这是我的路线:
devise_for :users
单击链接后,出现以下路由错误:
No route matches {:controller=>"devise/admin"}
我不明白我在做什么错。
这是设计路线:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session GET /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format)
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
如果我没记错的话,我认为“更改密码”链接的路径为edit_password_url
。
在没有看到更多代码的情况下,我能提供的最好的解决方案就是将dev撕掉,然后放回去。只需运行rails d命令,然后反转创建了devise的generate命令并重新开始。
您需要告诉Rails您正在编辑谁的密码
正确的方法是这样的
<li><%= link_to "Change your password", edit_user_registration_path(current_user) %>
current_user是由devise提供的帮助程序。 希望能帮助到你!
如果您有一个设计模型User ,那么可以使用以下路径将其路由到更改密码页面:
edit_user_registration_path
然后可以在视图中像这样使用它:
<%= link_to 'Change Password', edit_user_registration_path %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.