2012-10-26 39 views
0

我正在爲管理員創建表單並列出,編輯和刪除用戶。我嘗試了許多不同的變體來刪除用戶,但沒有任何作用。我想知道是否因爲我需要在我的routes.rb中使用devise_for :usersresources :users。這是因爲我有上傳/附件鏈接到用戶。但這裏是我的鏈接設計/刪除用戶錯誤

<%= link_to 'Delete',user, :method => 'delete', :confirm => 'Are you sure?' %> 

而且我的routes.rb

# devise_for :users 
devise_for :users do 
    get "https://stackoverflow.com/users/sign_out" => "devise/sessions#destroy", :as => :destroy_user_session 
end 
resources :users do 
    resources :attachments 
end 

我收到的錯誤是The action 'destroy' could not be found for UsersController.

但我的用戶控制器具有

def destroy 
    @user = User.find(params[:id]).destroy 
    redirect_to admin_index, :flash => { :success => 'User was successfully deleted.' } 
end 
+0

這與Devise沒有任何關係。看起來類似於[這個SO問題](http://stackoverflow.com/questions/4606860/rails-3-link-to-to-destroy-not-working)。那裏的答案建議使用一個按鈕,這可能是一個好主意,但鏈接也適用於Rails。這可能是您的Ajax JavaScript驅動程序的一個問題。 – numbers1311407

回答

1

如果你是沒有使用Ajax的請求,問題是你使用link_to

爲了送:方法=>「刪除」,你必須使用一個按鈕,絕對是這樣的:

http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist

​​

由於破壞性行動必須與表單提交進行

+0

嘗試過按鈕...同樣的錯誤 – LABLUEZ

+0

請檢查兩件事,首先,使用耙路徑並向我發送您的路線,其次檢查您是否在關閉控制器之前定義了de destroy方法。 – felipeclopes

+0

這裏是我的用戶控制器的一部分銷燬 – LABLUEZ