我在我的rails应用程序中使用了用于身份验证的设计。我可以签到和退出,也可以注册。但是,一旦用户被登录,我希望为用户提供一种修改其登录密码的方法。为此,应用程序提供了一个指向'edit_user_registration_path'的链接,如下面的rake路由输出所示。
当用户单击下面的“修改密码”链接时,
<li><%= link_to "Change Password", edit_user_registration_path %></li>
我得到以下错误
ActionController::RoutingError (No route matches {:action=>"edit", :controller=>"users"}):
我有一个带有显示、编辑和更新操作的UsersController。编辑操作是更新用户模型的其他列。
路线设置如下:
devise_for :users
resources :users, only: [:show, :edit, :update]
耙路输出-
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
控制台日志如下
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'
发布于 2013-02-22 15:43:56
上述日志中的重要行是:
ActionController::RoutingError (没有路由匹配{:action=>“编辑”,:controller=>“用户”}):app/view/layout/_#en0#er.html.erb:22:in:action=>
在这种情况下,路由需要与所有的参数匹配。
edit_user GET /users/:id/edit(.:format) users#edit
如果提供no :id,则不匹配。
而不是:
<%= link_to "Settings", edit_user_path %>
将current_user
作为参数发送:
<%= link_to "Settings", edit_user_path(current_user) %>
https://stackoverflow.com/questions/14999192
复制相似问题