1

每当我在登录时转到 /users/edit 时都会收到此错误:

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

为什么用户/编辑试图在用户控制器中查找显示操作?

路线.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
4

1 回答 1

1

奇怪的!

因此,我逐步完成了所有最后的更改,发现问题在于位于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除 layout/application.html.erb 文件之外的任何地方的链接时,路由工作正常。

于 2012-11-20T20:43:59.657 回答