I am using devise for authentication in my rails app. I am able to sign in and out and also sign up. However once the user is signed in, I want to provide a means for the user to modify his sign in password. For that the app provides a link to the 'edit_user_registration_path' which is shown in the rake routes output below.
When the user clicks on the modify password link below,
<li><%= link_to "Change Password", edit_user_registration_path %></li>
I get the following error
ActionController::RoutingError (No route matches {:action=>"edit", :controller=>"users"}):
I have a UsersController with show, edit and update actions. The edit action is to update the other columns of the Users model.
The routes are set up as below
devise_for :users
resources :users, only: [:show, :edit, :update]
rake route output -
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /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) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
root / home#index
The console log is below
Started GET "/users/edit" for 127.0.0.1 at 2013-02-21 15:21:38 +0530
Processing by Devise::RegistrationsController#edit as HTML
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Rendered devise/registrations/edit.html.erb within layouts/application (15.9ms)
Rendered layouts/_shim.html.erb (0.0ms)
Rendered layouts/_messages.html.erb (0.1ms)
Rendered layouts/_header.html.erb (42.5ms)
Completed 500 Internal Server Error in 99ms
ActionController::RoutingError (No route matches {:action=>"edit", :controller=>"users"}):
app/views/layouts/_header.html.erb:22:in `_app_views_layouts__header_html_erb__267315279__621159918'
app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb__982964301_89714280'
The important lines in the logs above are:
ActionController::RoutingError (No route matches {:action=>"edit", :controller=>"users"}): app/views/layouts/_header.html.erb:22:in `_app_views_layouts__header_html_erb__267315279__621159918'
Routes need to match with all it's params, in this case
edit_user GET /users/:id/edit(.:format) users#edit
is not matched when no :id is supplied.
Instead of:
<%= link_to "Settings", edit_user_path %>
Send the current_user
as a parameter:
<%= link_to "Settings", edit_user_path(current_user) %>
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.