简体   繁体   English

设计/删除用户错误

[英]Devise/ Delete user Error

I am creating a form for an admin to go in and list, edit and delete users. 我正在为管理员创建一个表单,以列出,编辑和删除用户。 I have tried many different variations for deleting a user and nothing works. 我已经尝试了许多不同的变体来删除用户,但没有任何效果。 I am wondering if it is because I need to use devise_for :users and resources :users in my routes.rb. 我想知道是否是因为我需要在我的route.rb中使用devise_for :usersresources :users This is because I have uploads/attachments linked to users. 这是因为我有链接到用户的上载/附件。 But here is my link 但这是我的链接

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

And my routes.rb 还有我的routes.rb

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

The error I am receiving is The action 'destroy' could not be found for UsersController. 我收到的错误The action 'destroy' could not be found for UsersController.

But my users controller has 但是我的用户控制器有

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

If you are not using ajax for the requests, the problem is taht you ar using a link_to 如果您没有使用ajax来处理请求,那么问题就出在使用link_to

In order to send the :method => 'delete' you have to use a button, jus like this: 为了发送:method =>'delete',您必须使用一个按钮,就像这样:

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

Because destructive action must be performed with a form submission: 由于必须在提交表单时执行破坏性操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM