簡體   English   中英

為edit_user_registration和用戶/ edit設計路由錯誤

[英]Devise routing error for edit_user_registration and users/edit

每當登錄后進入/ users / edit時,都會出現此錯誤:

No route matches {:action=>"show", :controller=>"users"}

為什么用戶/編輯試圖在用戶控制器中查找show動作?

routes.rb

  devise_for :users do
    get 'users', :to => 'users#show', :as => :user_root # Rails 3
  end

  resources :users, :only => [:index, :show]

  authenticated :user do
    root :to => 'home#index'
  end

  root :to => 'home#index'

耙路:

 user_root                GET    /users(.:format)               users#show
 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(.:forma        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
 users                    GET    /users(.:format)               users#index
 user                     GET    /users/:id(.:format)           users#show
 root                     /                                     home#index
 root                     /                                     home#index

奇怪的!

因此,我完成了所有我的最后更改,發現問題出在views / layouts / application.html.erb中的以下代碼行:

<%= link_to current_user.email, user_path  %>

由於某些原因,當它們是布局文件中的user_path的鏈接時,站點中的路由會變得一團糟。

為了解決這個問題,我只是將user_path更改為current_user所以我的新鏈接如下所示:

<%= link_to current_user.email, current_user  %>

真正奇怪的是,當您使用布局user_path文件以外的任何位置都指向user_path的鏈接時,路由工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM