[英]What is the rails reference for a custom edit action not showing in rake routes
I have a password_resets controller and I want to make the URL prettier for just the edit action. 我有一个password_resets控制器,并且我想使URL仅用于编辑操作。
This is in my routes file: 这是在我的路线文件中:
get 'resetpassword/:id/edit' => 'password_resets#edit'
which I've tested and it works! 我已经测试过并且可以使用! The hard thing is that now I don't know how to access it. 困难的是,现在我不知道如何访问它。
My bin/rake routes looks like this: 我的垃圾箱/耙线路线如下所示:
forgotpassword GET /forgotpassword(.:format) password_resets#new
GET /resetpassword/:id/edit(.:format) password_resets#edit
password_resets POST /password_resets(.:format) password_resets#create
new_password_reset GET /password_resets/new(.:format) password_resets#new
edit_password_reset GET /password_resets/:id/edit(.:format) password_resets#edit
password_reset PATCH /password_resets/:id(.:format) password_resets#update
PUT /password_resets/:id(.:format) password_resets#update
Namely, my custom URL doesn't have a prefix to it. 即,我的自定义URL没有前缀。 So how do I access it in my code? 那么如何在代码中访问它呢?
This is what I have which works in the code but doesn't use the custom url. 这就是我在代码中可以使用的但不使用自定义网址的内容。
<%= edit_password_reset_url(@user.reset_token, email: @user.email) %>
You need to name your route: 您需要命名您的路线:
get 'resetpassword/:id/edit' => 'password_resets#edit', as: :reset_password_pretty
There is the guide for that: http://guides.rubyonrails.org/routing.html 有相应的指南: http : //guides.rubyonrails.org/routing.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.