I have a password_resets controller and I want to make the URL prettier for just the edit action.
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. 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
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.