【发布时间】:2012-11-20 18:45:44
【问题描述】:
每当我在登录时转到 /users/edit 时都会收到此错误:
No route matches {:action=>"show", :controller=>"users"}
为什么用户/编辑试图在用户控制器中查找显示操作?
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
【问题讨论】:
-
这是因为你有
GET /users/:id(.:format)和GET /users/edit(.:format)。所以也许设计不知道:id和edit是不同的,它只是认为它们是/users/路径的相同参数。我之前遇到过这个问题,我的解决方案是为用户/节目制作另一条路线:match 'profiles/:id', to: 'users#show', as: :profile。
标签: ruby-on-rails devise routes