0

我在我的 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]

rake 路由输出 -

    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'
4

1 回答 1

1

上面日志中的重要行是:

ActionController::RoutingError (没有路由匹配 {:action=>"edit", :controller=>"users"}): app/views/layouts/_header.html.erb:22:in `_app_views_layouts__header_html_erb__267315279__621159918'

在这种情况下,路由需要与它的所有参数匹配

edit_user GET    /users/:id/edit(.:format)      users#edit

未提供 :id 时不匹配。

代替:

<%= link_to "Settings", edit_user_path %>

current_user作为参数发送:

<%= link_to "Settings", edit_user_path(current_user) %>
于 2013-02-22T15:43:56.407 回答