我正在使用设计进行身份验证。尝试删除用户时出现了我的问题。我收到以下 ActiveRecord::RecordNotFound 错误找不到 id=users 的用户
错误发生在:
before_filter :authenticate_user!, :except => [:show]
def show
@user = User.find(params[:id])
end
传递的参数是:
{"controller"=>"users", "action"=>"show", "id"=>"users"}
我一直想知道这个错误是否与我为设计定制创建的类 RegistrationsController < Devise::RegistrationsController 有关,但我不确定。
我的直觉告诉我,这确实是一个路由问题。这是我的路线文件:
Music::Application.routes.draw do
# resources :users
devise_scope :user do
get "/edit/account/:id" , to: "devise/registrations#edit" , :as => "edit_account"
get "/login" , to: "devise/sessions#new" , :as => "login"
get "/logout" , to: "devise/sessions#destroy" , :as => "logout"
end
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations" }
resources :contact_us_emails
get('/about-us', { :controller => "WelcomePages", :action => 'about', :as => 'about_us'})
get('/contact_us', { :controller => "WelcomePages", :action => 'contact_us', :as => 'contact_us'})
get('/search_collaborators', { :controller => "SongRooms", :action => 'search_collaborators', :as => 'search_collaborators'})
resources :searches do
collection do
get '/song_rooms/:query', :controller => "searches", :action => 'song_rooms', :as => 'search_song_rooms'
get '/users/:query', :controller => "searches", :action => 'users', :as => 'search_users'
get '/final_songs/:query', :controller => "searches", :action => 'final_songs', :as => 'search_final_songs'
get '/search_and_invite_facebok_friends/:user_id', :controller => "searches", :action => "search_and_invite_facebok_friends", :as => 'invite_fb_friends'
end
end
match 'download/:id' => 'versions#download', :as => :download
match '/musicians' => 'searches#musicians', :via => :get, :as => 'musicians'
match '/producers' => 'searches#producers', :via => :get, :as => 'producers'
match '/accept/:id' => 'requests#accept', :via => :get, :as => 'accept'
match '/deny/:id' => 'requests#deny', :via => :get, :as => 'deny'
match '/users/:id' => 'devise/registrations#destroy', :via => :delete, :as => 'cancel_registration'
resources :versions do
resources :messages
member do
post :vote
get :mark_as_final
get :unmark_as_final
end
end
post('/collaborators', {:controller => "Collaborators", :action => 'create', :as => 'create_collaborator'})
delete('song_rooms/:id/collaborators/:id', { :controller => "Collaborators", :action => 'destroy', :as => 'delete_collaborator'})
resources :song_rooms do
member do
get 'choose_final_song'
end
resources :collaborators
end
resources :user_song_uploads
# resources :users
post('/user/:id/vote', { :controller => "Users", :action => 'vote', :as => 'user_vote'})
match '/:id', :to => "users#show", :as => :user, :via => :get
authenticated :user do
root :to => "welcome_pages#home" , :as => "user_home"
end
root :to => "welcome_pages#index" , :as => "home"
end
最后我的取消链接到操作是这样的:
<%= link_to "Cancel my account", registration_path(resource), :data => { :confirm => "Are you sure?" }, :method => :delete %>
我还尝试为 resource_name、@user、@user.id、current_user、current_user.id 切换资源。
谢谢你的帮助!!