设计/删除用户错误

时间:2012-10-26 14:18:12

标签: ruby-on-rails devise

我正在创建一个表单,供管理员进入并列出,编辑和删除用户。我已经尝试了许多不同的变体来删除用户,但没有任何作用。我想知道是否因为我需要在我的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 "/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

1 个答案:

答案 0 :(得分:1)

如果你没有在请求中使用ajax,问题就是使用link_to

为了发送:method =&gt; '删除'你必须使用一个按钮,就像这样:

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

因为必须使用表单提交执行破坏性操作:

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